package GUI; import java.awt.*; import java.awt.event.*; public class TFMathTest extends Frame{ TextField num1; TextField num2; TextField sum; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub new TFMathTest().launchFrame(); } public void launchFrame() { num1 = new TextField(); num2 = new TextField(); sum = new TextField(); num1.setColumns(10); num2.setColumns(10); sum.setColumns(15); setLayout(new FlowLayout()); //setSize(500, 30); Label lblPlus = new Label("+"); Button btnEqual = new Button("="); btnEqual.addActionListener(new MyListener(this)); add(num1); add(lblPlus); add(num2); add(btnEqual); add(sum); pack(); setVisible(true); } } class MyListener implements ActionListener { private TFMathTest tfmt; public MyListener(TFMathTest tfmt) { this.tfmt = tfmt; } public void actionPerformed(ActionEvent e) { String s1 = tfmt.num1.getText(); String s2 = tfmt.num2.getText(); int i1 = Integer.parseInt(s1); int i2 = Integer.parseInt(s2); tfmt.sum.setText(String.valueOf(i1 + i2)); } }
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
import java.awt.*;
import java.awt.event.*;
public class TFMathTest extends Frame{
TextField num1;
TextField num2;
TextField sum;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new TFMathTest().launchFrame();
}
public void launchFrame()
{
num1 = new TextField();
num2 = new TextField();
sum = new TextField();
num1.setColumns(10);
num2.setColumns(10);
sum.setColumns(15);
setLayout(new FlowLayout());
//setSize(500, 30);
Label lblPlus = new Label("+");
Button btnEqual = new Button("=");
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
- 粉丝: 0
- 资源: 4
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)