| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 989 人关注过本帖
标题:一道JAVA题... ...
取消只看楼主 加入收藏
樱尔
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2005-10-3
收藏
 问题点数:0 回复次数:0 
一道JAVA题... ...

题目目的: 使用SWING设计界面,在文本框输入半径数值,点击"计算"按钮,在LABEL中输出圆面积或周长. 面积:*半径*半径*3.14 周长:半径*2*3.14 程序要求:GUI界面我已经布置好 但他要求要在NORTH部分,加入BUTTONGROUP,即把(RADIOBUTTON)加入BUTTONGROUP中,这点我没明白. 另外 1要使用Double.parseDouble(String a)将字符串转换为DOUBLE类型 2使用NumberFormatException捕获 3将无线按扭的isSelected()方法判断相应的无线按扭是否被选中 我的代码如下: import java.awt.*; import java.awt.event.*; import javax.swing.*;

public class Natsumi extends JFrame { JPanel p1,p2; JLabel t1,t2; JTextField f1; JRadioButton r1,r2; JButton b1; public Natsumi() { p1=new JPanel(); p2=new JPanel(); t1=new JLabel("半径"); t2=new JLabel("计算结果为:"); r1=new JRadioButton("面积"); r2=new JRadioButton("周长",true); f1=new JTextField(15); b1=new JButton("计算"); //b1.addActionListener(this); this.setSize(290,210); this.setTitle("Natsumi Abe"); p1.setLayout(new FlowLayout()); p2.setLayout(new GridLayout(2,2)); this.getContentPane().add(p1,BorderLayout.NORTH); this.getContentPane().add(p2); p1.add(r1); p1.add(r2); p2.add(t1); p2.add(f1); p2.add(b1); p2.add(t2); this.setVisible(true); } public void actionPerformed(ActionEvent e) { Double answer; //Double a; Double PI=new Double(3.14); String arr=new String(); Double a=Double.parseDouble(arr); f1.setText(a); if(e.getSource()==b1){ if(r1.isSelected()==true){ answer=a*a*PI; } else answer=a*2*PI; t2.setText("计算结果为:"+answer); } } 有错误,且没思路 有没有高手帮我指导下

搜索更多相关主题的帖子: JAVA 
2005-10-19 16:24
快速回复:一道JAVA题... ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018045 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved