java编程题 编写图形应用程序 计算器和文本编辑器 发我QQ邮箱2864570899@qq.com 40
计算器和文本编辑器各一个每句话都写上完整注释吧因为我是初学者根本什么都不懂老师上课要问每句代码的意思。。。摆脱了大神们!!!!我一定会追加悬赏分的!!!发我QQ邮箱286...
计算器和文本编辑器各一个
每句话都写上完整注释吧 因为我是初学者 根本什么都不懂 老师上课要问每句代码的意思。。。摆脱了 大神们!!!!我一定会追加悬赏分的!!!发我QQ邮箱2864570899@qq.com 展开
每句话都写上完整注释吧 因为我是初学者 根本什么都不懂 老师上课要问每句代码的意思。。。摆脱了 大神们!!!!我一定会追加悬赏分的!!!发我QQ邮箱2864570899@qq.com 展开
2个回答
展开全部
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.math.*;
public class Exe_3{
public static void main(String args[]){
MathWindow win=new MathWindow();
}
}
class MathWindow extends JFrame implements ActionListener{
JLabel label1,label2,label3;
JTextField text1,text2,text3;
JButton button1,button2,button3,button4;
JPanel pSouth,pNorth;
MathWindow(){
label1=new JLabel("第一个数");
label2=new JLabel("第二个数");
label3=new JLabel("结果");
text1=new JTextField(5);
text2=new JTextField(5);
text3=new JTextField(15);
button1=new JButton("加");
button2=new JButton("减");
button3=new JButton("乘");
button4=new JButton("除");
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
pNorth=new JPanel();
pSouth=new JPanel();
pNorth.add(label1);
pNorth.add(text1);
pNorth.add(label2);
pNorth.add(text2);
pNorth.add(label3);
pNorth.add(text3);
pSouth.add(button1);
pSouth.add(button2);
pSouth.add(button3);
pSouth.add(button4);
add(pNorth,BorderLayout.NORTH);
add(pSouth,BorderLayout.SOUTH);
setBounds(100,100,400,250);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
double s;
if(e.getSource()==button1){
try{
s=Double.parseDouble(text1.getText())+Double.parseDouble(text2.getText());
text3.setText(String.valueOf(s));
}
catch(NumberFormatException ee){
text3.setText("请输入数字字符");
text1.setText(null);
text2.setText(null);
}
}
if(e.getSource()==button2)
{
try{
s=Double.parseDouble(text1.getText())-Double.parseDouble(text2.getText());
text3.setText(String.valueOf(s));
}
catch(NumberFormatException ee){
text3.setText("请输入数字字符");
text1.setText(null);
text2.setText(null);
}
}
if(e.getSource()==button3){
try{
s=Double.parseDouble(text1.getText())*Double.parseDouble(text2.getText());
text3.setText(String.valueOf(s));
}
catch(NumberFormatException ee){
text3.setText("请输入数字字符");
text1.setText(null);
text2.setText(null);
}
}
if(e.getSource()==button4){
try{
s=Double.parseDouble(text1.getText())/Double.parseDouble(text2.getText());
text3.setText(String.valueOf(s));
}
catch(NumberFormatException ee){
text3.setText("请输入数字字符");
text1.setText(null);
text2.setText(null);
}
}
}
}
import java.awt.event.*;
import javax.swing.*;
import java.math.*;
public class Exe_3{
public static void main(String args[]){
MathWindow win=new MathWindow();
}
}
class MathWindow extends JFrame implements ActionListener{
JLabel label1,label2,label3;
JTextField text1,text2,text3;
JButton button1,button2,button3,button4;
JPanel pSouth,pNorth;
MathWindow(){
label1=new JLabel("第一个数");
label2=new JLabel("第二个数");
label3=new JLabel("结果");
text1=new JTextField(5);
text2=new JTextField(5);
text3=new JTextField(15);
button1=new JButton("加");
button2=new JButton("减");
button3=new JButton("乘");
button4=new JButton("除");
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
pNorth=new JPanel();
pSouth=new JPanel();
pNorth.add(label1);
pNorth.add(text1);
pNorth.add(label2);
pNorth.add(text2);
pNorth.add(label3);
pNorth.add(text3);
pSouth.add(button1);
pSouth.add(button2);
pSouth.add(button3);
pSouth.add(button4);
add(pNorth,BorderLayout.NORTH);
add(pSouth,BorderLayout.SOUTH);
setBounds(100,100,400,250);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
double s;
if(e.getSource()==button1){
try{
s=Double.parseDouble(text1.getText())+Double.parseDouble(text2.getText());
text3.setText(String.valueOf(s));
}
catch(NumberFormatException ee){
text3.setText("请输入数字字符");
text1.setText(null);
text2.setText(null);
}
}
if(e.getSource()==button2)
{
try{
s=Double.parseDouble(text1.getText())-Double.parseDouble(text2.getText());
text3.setText(String.valueOf(s));
}
catch(NumberFormatException ee){
text3.setText("请输入数字字符");
text1.setText(null);
text2.setText(null);
}
}
if(e.getSource()==button3){
try{
s=Double.parseDouble(text1.getText())*Double.parseDouble(text2.getText());
text3.setText(String.valueOf(s));
}
catch(NumberFormatException ee){
text3.setText("请输入数字字符");
text1.setText(null);
text2.setText(null);
}
}
if(e.getSource()==button4){
try{
s=Double.parseDouble(text1.getText())/Double.parseDouble(text2.getText());
text3.setText(String.valueOf(s));
}
catch(NumberFormatException ee){
text3.setText("请输入数字字符");
text1.setText(null);
text2.setText(null);
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-05-13
展开全部
呵呵,首先我是来完成任务的。虽然题目简单,但是要花时间。提高悬赏?看了下你还剩10个财富。单独一个如果不是别人写好的,专门给你写就算你100分也没有人写何况还要写注释。可以百度源码有很多先下下来,然后自己看,一边看一边查Api,没有什么难度的,在不看不懂百度来问。这样会更好。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询