返回列表 發帖
  1. import java.awt.BorderLayout;
  2. import java.awt.EventQueue;

  3. import javax.swing.JFrame;
  4. import javax.swing.JPanel;
  5. import javax.swing.border.EmptyBorder;
  6. import javax.swing.JButton;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.Font;
  10. import javax.swing.JTextArea;
  11. import javax.swing.JTextPane;
  12. import javax.swing.JTextField;


  13. public class Click extends JFrame {

  14.         private JPanel contentPane;
  15.         private JTextField tf1;
  16.     public int click=0;
  17.         /**
  18.          * Launch the application.
  19.          */
  20.         public static void main(String[] args) {
  21.                
  22.                 EventQueue.invokeLater(new Runnable() {
  23.                         public void run() {
  24.                                 try {
  25.                                         Click frame = new Click();
  26.                                         frame.setVisible(true);
  27.                                 } catch (Exception e) {
  28.                                         e.printStackTrace();
  29.                                 }
  30.                         }
  31.                 });
  32.         }

  33.         /**
  34.          * Create the frame.
  35.          */
  36.         public Click() {
  37.                 setTitle("\u9EDE\u64CA\u8A08\u6578\u5668");
  38.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  39.                 setBounds(100, 100, 364, 93);
  40.                 contentPane = new JPanel();
  41.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  42.                 setContentPane(contentPane);
  43.                 contentPane.setLayout(null);
  44.                
  45.                 JButton btn2 = new JButton("\u6B78\u96F6");
  46.                 btn2.setFont(new Font("微軟正黑體", Font.PLAIN, 14));
  47.                 btn2.addActionListener(new ActionListener() {
  48.                         public void actionPerformed(ActionEvent arg0)
  49.                         {
  50.                                 click=0;
  51.                                 tf1.setText(String.valueOf(click));
  52.                         }
  53.                 });
  54.                 btn2.setBounds(250, 14, 88, 32);
  55.                 contentPane.add(btn2);
  56.                
  57.                 JButton btn1 = new JButton("\u9EDE\u64CA");
  58.                 btn1.setFont(new Font("微軟正黑體", Font.PLAIN, 16));
  59.                 btn1.addActionListener(new ActionListener() {
  60.                         public void actionPerformed(ActionEvent e)
  61.                         {
  62.                                 click++;
  63.                                 tf1.setText(String.valueOf(click));
  64.                         }
  65.                 });
  66.                 btn1.setBounds(152, 13, 88, 32);
  67.                 contentPane.add(btn1);
  68.                
  69.                 tf1 = new JTextField();
  70.                 tf1.addActionListener(new ActionListener() {
  71.                         public void actionPerformed(ActionEvent e)
  72.                         {
  73.                         tf1.setText(String.valueOf(click));
  74.                         }
  75.                 });
  76.                 tf1.setFont(new Font("Consolas", Font.PLAIN, 14));
  77.                 tf1.setBounds(10, 14, 132, 28);
  78.                 contentPane.add(tf1);
  79.                 tf1.setColumns(10);
  80.         }
  81. }
複製代碼

TOP

返回列表