| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 455 人关注过本帖
标题:[求助]实现这个程序的功能:实现结果的输出
只看楼主 加入收藏
weixing86
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-3-24
收藏
 问题点数:0 回复次数:3 
[求助]实现这个程序的功能:实现结果的输出

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class CircleCLT//圆的计算布局第一个。
{
JFrame frame;
JLabel l1,l2,l3;
JTextField tf1,tf2,tf3;
JButton b1,b2,b3,b4;
JPanel p1,p2,p3;
JTextArea ta;
public static void main(String[] args)
{
CircleCLT cc=new CircleCLT();
cc.go();
}
public void go()
{

frame=new JFrame("圆的计算");

l1=new JLabel("请输入圆的半径",l1.LEFT);
tf1=new JTextField(10);
b1=new JButton("确定");
b1.setForeground(Color.white);
b1.setBackground(Color.black);
b2=new JButton("重置");
b2.setForeground(Color.black);
b2.setBackground(Color.white);
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
tf1.setText("");//setText()是修改文本的方法,让它的新参数为空(""),就等于清空了三个文本域。
tf2.setText("");
tf3.setText("");
}
});
p1=new JPanel();
p1.add(l1);
p1.add(tf1);
p1.add(b1);
p1.add(b2);

l2=new JLabel("圆的面积");
tf2=new JTextField(10);
p2=new JPanel();
p2.add(l2);
p2.add(tf2);

l3=new JLabel("圆的周长");
tf3=new JTextField(10);
p3=new JPanel();
p3.add(l3);
p3.add(tf3);

ta=new JTextArea(50,1);
b3=new JButton("清除");//如果逗号用输入汉字时所用的逗号,会出现"非法的标识符"的错误
b3.setForeground(Color.black);
b3.setBackground(Color.white);
b3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ta.setText("");
}
});
JScrollPane p4=new JScrollPane(ta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
tf1.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e)
{
String h=tf1.getText();
ta .append("\n圆的半径:"+h);
}
});
tf2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String w=tf2.getText();
ta .append("\n圆的面积:"+w);
}
});
tf3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String y=tf3.getText();
ta .append("\n圆的周长:"+y);
}
});
b4=new JButton("拷贝");
b4.setForeground(Color.black);
b4.setBackground(Color.white);
b4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String h=tf1.getText();
ta .append("\n圆的半径:"+h);
String w=tf2.getText();
ta .append("\n圆的面积:"+w);
String y=tf3.getText();
ta .append("\n圆的周长:"+y);
}
});
JPanel p6=new JPanel();
p6.add(b3);
p6.add(b4);
JPanel p5=new JPanel();
p5.setLayout(new GridLayout(1,2));
p5.add(p4);
p5.add(p6);

Container cp=frame.getContentPane();
cp.setLayout(new GridLayout(4,1));
cp.add(p1);
cp.add(p2);
cp.add(p3);
cp.add(p5);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(450,300);
frame.setVisible(true);
}
}

搜索更多相关主题的帖子: 结果 输出 
2007-04-04 20:41
amyvmiwei
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-4-4
收藏
得分:0 

在这里我的声明-->我只是按你的要求完成了一些 但是不是精华的程序,以下靠你自己完成了.呵呵~!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class CircleCLT//圆的计算布局第一个。
{
JFrame frame;
JLabel l1,l2,l3;
JTextField tf1,tf2,tf3;
JButton b1,b2,b3,b4;
JPanel p1,p2,p3;
JTextArea ta;
final double PI = 3.14; //PI为常量派。
public static void main(String[] args)
{
CircleCLT cc=new CircleCLT();
cc.go();
}
public void go()
{

frame=new JFrame("圆的计算");

l1=new JLabel("请输入圆的半径",l1.LEFT);
tf1=new JTextField(10);
b1=new JButton("确定");
b1.setForeground(Color.white);
b1.setBackground(Color.black);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
Integer banjing = Integer.parseInt(tf1.getText()); //
Double zhouchang = banjing * PI * 2;
Double mianji = banjing * banjing * PI;

String zhouchang2 = zhouchang.toString();
String mianji2 = mianji.toString();
tf3.setText(zhouchang2);
tf2.setText(mianji2);
}
});
b2=new JButton("重置");
b2.setForeground(Color.black);
b2.setBackground(Color.white);
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
tf1.setText("");//setText()是修改文本的方法,让它的新参数为空(""),就等于清空了三个文本域。
tf2.setText("");
tf3.setText("");
}
});
p1=new JPanel();
p1.add(l1);
p1.add(tf1);
p1.add(b1);
p1.add(b2);

l2=new JLabel("圆的面积");
tf2=new JTextField(10);
p2=new JPanel();
p2.add(l2);
p2.add(tf2);

l3=new JLabel("圆的周长");
tf3=new JTextField(10);
p3=new JPanel();
p3.add(l3);
p3.add(tf3);

ta=new JTextArea(50,1);
b3=new JButton("清除");//如果逗号用输入汉字时所用的逗号,会出现"非法的标识符"的错误
b3.setForeground(Color.black);
b3.setBackground(Color.white);
b3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ta.setText("");
}
});
JScrollPane p4=new JScrollPane(ta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
tf1.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e)
{
String h=tf1.getText();
ta .append("\n圆的半径:"+h);
}
});
tf2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String w=tf2.getText();
ta .append("\n圆的面积:"+w);
}
});
tf3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String y=tf3.getText();
ta .append("\n圆的周长:"+y);
}
});
b4=new JButton("拷贝");
b4.setForeground(Color.black);
b4.setBackground(Color.white);
b4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String h=tf1.getText();
ta .append("\n圆的半径:"+h);
String w=tf2.getText();
ta .append("\n圆的面积:"+w);
String y=tf3.getText();
ta .append("\n圆的周长:"+y);
}
});
JPanel p6=new JPanel();
p6.add(b3);
p6.add(b4);
JPanel p5=new JPanel();
p5.setLayout(new GridLayout(1,2));
p5.add(p4);
p5.add(p6);

Container cp=frame.getContentPane();
cp.setLayout(new GridLayout(4,1));
cp.add(p1);
cp.add(p2);
cp.add(p3);
cp.add(p5);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(450,300);
frame.setVisible(true);
}
}

2007-04-04 23:51
xiaoxuanfenz
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2007-4-5
收藏
得分:0 
哥们,太感谢了,可以告诉我你的QQ号吗?
2007-04-05 14:22
amyvmiwei
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-4-4
收藏
得分:0 
我也是个新手, 刚好就是这点懂,
你的代码 我有的还不懂嗫!~~~

呵呵~~~,互相交流 学习!
我QQ:271549506

2007-04-16 20:09
快速回复:[求助]实现这个程序的功能:实现结果的输出
数据加载中...
 
   



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

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