返回列表 發帖
  1. package bbs.istak.org.tw;

  2. import java.awt.BorderLayout;
  3. import java.awt.EventQueue;

  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import javax.swing.border.EmptyBorder;
  7. import javax.swing.GroupLayout;
  8. import javax.swing.GroupLayout.Alignment;
  9. import javax.swing.JLabel;
  10. import javax.swing.JButton;
  11. import java.awt.event.ActionListener;
  12. import java.awt.event.ActionEvent;

  13. public class Main extends JFrame {

  14.         private JPanel contentPane;
  15.         private int count =0;

  16.         /**
  17.          * Launch the application.
  18.          */
  19.         public static void main(String[] args) {
  20.                 EventQueue.invokeLater(new Runnable() {
  21.                         public void run() {
  22.                                 try {
  23.                                         Main frame = new Main();
  24.                                         frame.setVisible(true);
  25.                                 } catch (Exception e) {
  26.                                         e.printStackTrace();
  27.                                 }
  28.                         }
  29.                 });
  30.         }

  31.         /**
  32.          * Create the frame.
  33.          */
  34.         public Main() {
  35.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  36.                 setBounds(100, 100, 326, 171);
  37.                 contentPane = new JPanel();
  38.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  39.                 setContentPane(contentPane);
  40.                 contentPane.setLayout(null);
  41.                
  42.                 JLabel lblNewLabel = new JLabel("0");
  43.                 lblNewLabel.setBounds(10, 10, 98, 100);
  44.                 contentPane.add(lblNewLabel);
  45.                
  46.                 JButton btnNewButton = new JButton("\u9EDE\u64CA");
  47.                 btnNewButton.addActionListener(new ActionListener() {
  48.                         public void actionPerformed(ActionEvent e) {
  49.                                 lblNewLabel.setText(String.valueOf(++count));
  50.                         }
  51.                 });
  52.                 btnNewButton.setBounds(118, 49, 87, 23);
  53.                 contentPane.add(btnNewButton);
  54.                
  55.                 JButton btnNewButton_1 = new JButton("\u6B78\u96F6");
  56.                 btnNewButton_1.addActionListener(new ActionListener() {
  57.                         public void actionPerformed(ActionEvent e) {
  58.                                 lblNewLabel.setText("0");
  59.                                 count = 0;
  60.                         }
  61.                 });
  62.                 btnNewButton_1.setBounds(213, 49, 87, 23);
  63.                 contentPane.add(btnNewButton_1);
  64.         }

  65. }
複製代碼

TOP

返回列表