import java.awt.*;
import java.awt.event.*;
public class MPlus
{
public static void main(String[] args)
{
MyFrame f1=new MyFrame();
f1.launch();
}
}
class MyFrame extends Frame
{
super("Plus");
TextField t1;
TextField t2;
TextField t3;
public void launch(){
setLayout(new FlowLayout());
t1 = new TextField(10);
Label l1 = new Label("+");
t2 = new TextField(10);
Button b1 = new Button("=");
t3 = new TextField(15);
b1.addActionListener(new Monitor(this));
add(t1);
add(l1);
add(t2);
add(b1);
add(t3);
pack();
setVisible(true); }
}
class Monitor implements ActionListener
{
MyFrame f1 = null;
public Monitor(MyFrame f2){
f1 = f2;
}
public void actionPerformed(ActionEvent e){
int n1 = Integer.parseInt(f1.t1.getText());
int n2 = Integer.parseInt(f1.t2.getText());
f1.t3.setText(""+(n1+n2));
}
}
import java.awt.event.*;
public class MPlus
{
public static void main(String[] args)
{
MyFrame f1=new MyFrame();
f1.launch();
}
}
class MyFrame extends Frame
{
super("Plus");
TextField t1;
TextField t2;
TextField t3;
public void launch(){
setLayout(new FlowLayout());
t1 = new TextField(10);
Label l1 = new Label("+");
t2 = new TextField(10);
Button b1 = new Button("=");
t3 = new TextField(15);
b1.addActionListener(new Monitor(this));
add(t1);
add(l1);
add(t2);
add(b1);
add(t3);
pack();
setVisible(true); }
}
class Monitor implements ActionListener
{
MyFrame f1 = null;
public Monitor(MyFrame f2){
f1 = f2;
}
public void actionPerformed(ActionEvent e){
int n1 = Integer.parseInt(f1.t1.getText());
int n2 = Integer.parseInt(f1.t2.getText());
f1.t3.setText(""+(n1+n2));
}
}
解决方案 »
- SWT的多个CheckButton被设置默认选中,在不触发Selection事件时情况下如何获得被选中的button
- 关于if的,相信很多人和我一样有点不懂
- Java中Math.random()的取值问题,求助
- java的参数可不可以实现多选啊
- 如何加速成长为大型软件设计师和架构师?
- 如何实现21点游戏玩家与玩家游戏
- JFrame窗体怎么一开始就让它最大化?
- 为什么重载paint(graphics g)后,截面上的菜单没有了......在线等待!!!
- 一个jasperreport的奇怪现象,详情见内
- 请问“thinging in java”的第一版和第二版有什么区别呀?
- Panel不能设置大小
- 提取一个java文件中的所有字符串
{
super("Plus");
TextField t1;
TextField t2;
TextField t3;
public void launch(){
setLayout(new FlowLayout());
t1 = new TextField(10);
你这些的是啥啊???
class MyFrame extends Frame
{
public MyFrame(){
super("Plus");
}
TextField t1;
TextField t2;
TextField t3;
public void launch(){
setLayout(new FlowLayout());
t1 = new TextField(10);