(1) 编写一个java程序实现两数求和功能:在两个文本框里分别输入两个数字,单击“求和”按钮,则在第三

文本框里显示运算结果,参考界面如图所示 急~~~~~
2024-12-02 03:19:24
推荐回答(4个)
回答1:

【代码】Applet实现,页面选择gbk编码
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class Add extends Applet implements ActionListener
{
Label lblTwoNum = new Label ("请输入两个数字");
Label lblAdd = new Label ("此处显示答案");

TextField txtFirstNum = new TextField (2);
TextField txtSecNum = new TextField (2);
Button btnAdd = new Button ( "求和");

public void init()
{
add (lblTwoNum);
add (txtFirstNum);
add (txtSecNum);
add (btnAdd);
add (lblAdd);
this.resize(300,100);
btnAdd.addActionListener (this);
}

public void actionPerformed (ActionEvent e)
{
String firstNum = txtFirstNum.getText();
String secNum = txtSecNum.getText();
int add = Integer.parseInt(firstNum) + Integer.parseInt(secNum);
lblAdd.setText ("两数之和:"+ add);
}
}
如果不会调试可以百度Hi我~~

回答2:

你用的是SWT还是RCP啊 在RCP中实现很简单,只需相应的包即可

回答3:

你是谁,这么巧?

回答4:

Swing界面啊