该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import java.awt.*;
import javax.swing.*;
//import java.util.*;
public class lay
{
public static void main(String[] arps){
JFrame jframe=new JFrame("求和");
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setSize(400,300);
JPanel rootpanel=(JPanel)jframe.getContentPane();
rootpanel.setLayout(null);
JLabel label1=new JLabel("数字1");
label1.setFont(new Font("宋体",Font.PLAIN,13));
label1.setBounds(40, 30, 40, 15);
JLabel label2=new JLabel("数字2");
label2.setFont(new Font("宋体",Font.PLAIN,13));
label2.setBounds(200, 30, 40, 15);
JTextField txt1=new JTextField();
txt1.setBounds(72,25,96,20);
JTextField txt2=new JTextField();
txt2.setBounds(190,25,96,20);
JTextField txt3=new JTextField();
txt3.setBounds(140,200,96,20);
JPanel j1=new JPanel();
j1.setSize(400,100);
j1.setBackground(Color.cyan);
j1.add(label1);
//j1.add(txt1);
j1.add(label2);
//j1.add(txt2);
JButton b1=new JButton("求和");
JPanel j2=new JPanel();
j2.setSize(400,70);
j2.setBackground(Color.pink);
j2.setLocation(0,100);
j2.add(b1);
JPanel j3=new JPanel();
j3.setSize(400,130);
j3.setBackground(Color.green);
j3.setLocation(0,170);
int a = Integer.parseInt(txt1.getText());
int b = Integer.parseInt(txt2.getText());
int c = a+b;
String s=String.valueOf(c); //可能有错误地方
txt3.setText(s);
rootpanel.add(j1);
rootpanel.add(j2);
rootpanel.add(j3);
rootpanel.add(txt1);
rootpanel.add(txt2);
rootpanel.add(txt3);
jframe.setVisible(true);
}
}