一个Java小应用程序,界面有三个文本框和两个按钮,前两个文本框用于输入整数,第三个文本框用于输出结果
importjava.applet.*;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;class...
import java.applet.*;import javax.swing.*;
import java.awt.*; import java.awt.event.*;
class Panel1 extends JPanel{
JTextField text1, text2, text3;
JButton addButton,subButton;
Panel1(){
text1=new JTextField(10);
text2=new JTextField(10);
text3=new JTextField(10);
setLayout(new GridLayout(5,1));
addButton=new JButton("加");
subButton=new JButton("减");
add(text1);
add(text2);
add(text3);
add(addButton);
add(subButton);
}
}
public class Classl extends Applet implementsActionListener{
Pane1 panel;
public void init(){
setSize(100,200); panel=new Panel1();add(panel);
(panel.addButton).addActionListener(this);
(panel.subButton). addActionListener(this);
}
public void actionPerformed(ActionEvent e){
//这里是你要编写的代码 展开
import java.awt.*; import java.awt.event.*;
class Panel1 extends JPanel{
JTextField text1, text2, text3;
JButton addButton,subButton;
Panel1(){
text1=new JTextField(10);
text2=new JTextField(10);
text3=new JTextField(10);
setLayout(new GridLayout(5,1));
addButton=new JButton("加");
subButton=new JButton("减");
add(text1);
add(text2);
add(text3);
add(addButton);
add(subButton);
}
}
public class Classl extends Applet implementsActionListener{
Pane1 panel;
public void init(){
setSize(100,200); panel=new Panel1();add(panel);
(panel.addButton).addActionListener(this);
(panel.subButton). addActionListener(this);
}
public void actionPerformed(ActionEvent e){
//这里是你要编写的代码 展开
2个回答
展开全部
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == panel.addButton){
int t1 = Integer.parseInt(panel.text1.getText());
int t2 = Integer.parseInt(panel.text2.getText());
panel.text3.setText(t1 + t2 + "");
}
if (e.getSource() == panel.subButton){
int t1 = Integer.parseInt(panel.text1.getText());
int t2 = Integer.parseInt(panel.text2.getText());
panel.text3.setText(t1 - t2 + "");
}
}
2014-04-07
展开全部
很成功收到一条
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询