Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:各大虾帮忙看看~谢谢 [Re:kakaka0]
tcxmn





发贴: 10
积分: 0
于 2004-12-07 23:40 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
最终正确的代码如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Adder implements ActionListener {
JFrame AdderFrame;
JTextField TOprand1;
JTextField TOprand2;
JLabel LAdd, LSum;
JButton BAdd;
int i = 0;
//构造器---------------------------------------------------
public Adder() {
AdderFrame = new JFrame("AdderFrame");
TOprand1 = new JTextField("0.0");
TOprand2 = new JTextField("0.0");
LAdd = new JLabel("+");
LSum = new JLabel("= ");
BAdd = new JButton("Add!");
AdderFrame.getContentPane().setLayout(new FlowLayout());
AdderFrame.getContentPane().add(TOprand1);
AdderFrame.getContentPane().add(LAdd);
AdderFrame.getContentPane().add(TOprand2);
AdderFrame.getContentPane().add(LSum);
AdderFrame.getContentPane().add(BAdd);
AdderFrame.pack();
AdderFrame.setVisible(true);
BAdd.addActionListener(this);

AdderFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}//构造器结束----------------------------------------

//实现ActionListener接口--------------------------------------------
public void actionPerformed(ActionEvent event) {
i = (i = 1) % 2;
if (i == 1) {
int sum = (int) (Double.valueOf(TOprand1.getText()).doubleValue() +
Double.valueOf(TOprand2.getText()).doubleValue());
LSum.setText("=" + sum);
}
else {
TOprand1.setText("0.0");
TOprand2.setText("0.0");
LSum.setText("=");
}

}
//程序的入口--------------------------------------------
public static void main(String[] args) {
Adder adder = new Adder();
}
}


tcxmn edited on 2004-12-07 23:44


联想游戏(欢迎跟贴,哈)

话题树型展开
人气 标题 作者 字数 发贴时间
23344 各大虾帮忙看看~谢谢 kakaka0 1650 2004-12-02 10:53
19040 Re:各大虾帮忙看看~谢谢 miaomiao9527 19 2004-12-03 15:04
18680 Re:各大虾帮忙看看~谢谢 yorksaddam 19 2004-12-03 22:01
18703 Re:各大虾帮忙看看~谢谢 kakaka0 1714 2004-12-05 21:37
18694 Re:各大虾帮忙看看~谢谢 littledeer1974 60 2004-12-05 22:08
18851 Re:各大虾帮忙看看~谢谢 tcxmn 541 2004-12-07 23:30
18769 Re:各大虾帮忙看看~谢谢 tcxmn 131 2004-12-07 23:36
18748 Re:各大虾帮忙看看~谢谢 tcxmn 1736 2004-12-07 23:40
18799 Re:各大虾帮忙看看~谢谢 tcxmn 30 2004-12-07 23:45
18921 Re:各大虾帮忙看看~谢谢 kakaka0 11 2004-12-09 07:53

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923