上机作业

 1 import java.awt.BorderLayout;
 2         import java.awt.GridLayout;
 3         import java.awt.event.ActionEvent;
 4         import java.awt.event.ActionListener;
 5 
 6         import javax.swing.JButton;
 7         import javax.swing.JFrame;
 8         import javax.swing.JLabel;
 9         import javax.swing.JPanel;
10         import javax.swing.JTextField;
11 
12 public class test1 extends JFrame {
13     JFrame jf;
14     JPanel jp1,jp2,jp3,jp4,jp5,jp6,jp7,jp8,jp9;
15     JTextField jt1,jt2,jt3;
16     JButton jb1,jb2,jb3,jb4;
17     JLabel jl1,jl2;
18     public void creatjf(){
19         jf = new JFrame("couter");
20         jf.setLayout(null);
21         jf.setLayout(new GridLayout(3,3));
22 
23         jt1 = new JTextField(5);
24         jt2 = new JTextField(5);
25         jt3 = new JTextField(5);
26 
27         jb1 = new JButton("sum");
28         jb1.addActionListener(new ActionListener(){
29 
30             public void actionPerformed(ActionEvent arg0) {
31                 int number1 = Integer.parseInt(jt1.getText().trim());
32                 int number2 = Integer.parseInt(jt2.getText().trim());
33                 int sum =number1+number2;
34                 jt3.setText(String.valueOf(sum));
35             }
36 
37         });
38         jb2 = new JButton("cancel");
39         jb3 = new JButton();
40         jb4 = new JButton();
41 
42 
43         jl1 = new JLabel("newber"+1);
44         jl2 = new JLabel("number"+2);
45 
46         jf.add(jl1);
47         jf.add(jt1);
48         jf.add(jb3);
49         jf.add(jl2);
50         jf.add(jt2);
51         jf.add(jb4);
52         jf.add(jb1);
53 
54         jf.add(jt3);
55         jf.add(jb2);
56         jf.setSize(300, 300);
57         jf.setVisible(true);
58     }
59     public static void main(String[] args) {
60         // TODO 自动生成的方法存根
61 
62         new test1().creatjf();;
63     }
64 
65 }

 

你可能感兴趣的:(上机作业)