package unit5.lesson5;
import javax.swing.*;
import java.awt.*;
public class MyFrame extends JFrame {
JTextField T1 = new JTextField(5);
JTextField T2 = new JTextField(5);
JTextField H = new JTextField(10);
public MyFrame(String title){
super(title);
JPanel root = new JPanel();
this.setContentPane(root);
root.setLayout(new FlowLayout(0));
JButton button = new JButton("提取");
root.add(T1);
root.add(new JLabel("+"));
root.add(T2);
root.add(button);
root.add(H);
button.addActionListener((e)->{
getText();
});
}
public void getText(){
int s1 = Integer.parseInt(T1.getText());
int s2 = Integer.parseInt(T2.getText());
H.setText(""+(s1+s2));
T1.setText("");
T2.setText("");
}
}
Swing简陋加法计算器
最新推荐文章于 2024-08-02 18:52:04 发布