第四十次发博不知道用什么标题好
一个超级简单的可以使用的
1 package Test; 2 import java.awt.*; 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 6 import javax.swing.*; 7 8 public class Count { 9 JFrame f; 10 JPanel p; 11 JTextField tf1,tf2,tf3; 12 JLabel l1,l2,l3,l4; 13 JButton b1,b2; 14 15 public Count() { 16 f = new JFrame(); 17 p = new JPanel(); 18 tf1 = new JTextField(10); 19 tf2 = new JTextField(10); 20 tf3 = new JTextField(10); 21 22 l1 = new JLabel("加数1"); 23 l2 = new JLabel("加数2"); 24 l3 = new JLabel(); 25 l4 = new JLabel(); 26 b1 = new JButton("求和"); 27 b2 = new JButton("清除"); 28 29 f.setVisible(true); 30 f.setBounds(550, 200, 300, 300); 31 p.setLayout(new GridLayout(3,3)); 32 f.add(p); 33 34 p.add(l1); 35 p.add(tf1); 36 p.add(l3); 37 38 p.add(l2); 39 p.add(tf2); 40 p.add(l4); 41 42 p.add(b1); 43 p.add(tf3); 44 p.add(b2); 45 46 b1.addActionListener(new ActionListener() { 47 48 @Override 49 public void actionPerformed(ActionEvent e) { 50 int a = Integer.parseInt(tf1.getText()); 51 int b = Integer.parseInt(tf2.getText()); 52 tf3.setText(a+b+""); 53 54 // TODO Auto-generated method stub 55 56 } 57 }); 58 b2.addActionListener(new ActionListener() { 59 60 @Override 61 public void actionPerformed(ActionEvent e) { 62 tf1.setText(null); 63 tf2.setText(null); 64 tf3.setText(null); 65 66 // TODO Auto-generated method stub 67 68 } 69 }); 70 } 71 72 public static void main(String[] args) { 73 new Count(); 74 // TODO Auto-generated method stub 75 76 } 77 78 }
1 package Test; 2 import java.awt.*; 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 6 import javax.swing.*; 7 8 public class Count { 9 JFrame f; 10 JPanel p; 11 JTextField tf1,tf2,tf3; 12 JLabel l1,l2,l3,l4; 13 JButton b1,b2; 14 15 public Count() { 16 f = new JFrame(); 17 p = new JPanel(); 18 tf1 = new JTextField(10); 19 tf2 = new JTextField(10); 20 tf3 = new JTextField(10); 21 22 l1 = new JLabel("加数1"); 23 l2 = new JLabel("加数2"); 24 l3 = new JLabel(); 25 l4 = new JLabel(); 26 b1 = new JButton("求和"); 27 b2 = new JButton("清除"); 28 29 f.setVisible(true); 30 f.setBounds(550, 200, 300, 300); 31 p.setLayout(new GridLayout(3,3)); 32 f.add(p); 33 34 p.add(l1); 35 p.add(tf1); 36 p.add(l3); 37 38 p.add(l2); 39 p.add(tf2); 40 p.add(l4); 41 42 p.add(b1); 43 p.add(tf3); 44 p.add(b2); 45 46 b1.addActionListener(new ActionListener() { 47 48 @Override 49 public void actionPerformed(ActionEvent e) { 50 int a = Integer.parseInt(tf1.getText()); 51 int b = Integer.parseInt(tf2.getText()); 52 tf3.setText(a+b+""); 53 54 // TODO Auto-generated method stub 55 56 } 57 }); 58 b2.addActionListener(new ActionListener() { 59 60 @Override 61 public void actionPerformed(ActionEvent e) { 62 tf1.setText(null); 63 tf2.setText(null); 64 tf3.setText(null); 65 66 // TODO Auto-generated method stub 67 68 } 69 }); 70 } 71 72 public static void main(String[] args) { 73 new Count(); 74 // TODO Auto-generated method stub 75 76 } 77 78 }
计算器