返回列表 發帖
  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.JButton;
  8. import java.awt.FlowLayout;
  9. import javax.swing.GroupLayout;
  10. import javax.swing.GroupLayout.Alignment;
  11. import javax.swing.JLabel;
  12. import javax.swing.SwingConstants;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.ActionEvent;


  15. public class main extends JFrame {

  16.         private JPanel contentPane;
  17.         private int count =0;

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

  33.         /**
  34.          * Create the frame.
  35.          */
  36.         public main() {
  37.                 setTitle("\u9EDE\u64CA\u8A08\u6578\u5668");
  38.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  39.                 setBounds(100, 100, 322, 118);
  40.                 contentPane = new JPanel();
  41.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  42.                 setContentPane(contentPane);
  43.                 contentPane.setLayout(null);
  44.                
  45.                 JLabel Count = new JLabel("0");
  46.                 Count.setHorizontalAlignment(SwingConstants.CENTER);
  47.                 Count.setBounds(14, 22, 67, 32);
  48.                 contentPane.add(Count);
  49.                
  50.                 JButton btnNewButton = new JButton("\u9EDE\u64CA");
  51.                 btnNewButton.addActionListener(new ActionListener() {
  52.                         public void actionPerformed(ActionEvent arg0) {
  53.                                 
  54.                                 Count.setText(String.valueOf(++count));
  55.                         }
  56.                 });
  57.                 btnNewButton.setBounds(88, 13, 93, 51);
  58.                 contentPane.add(btnNewButton);
  59.                
  60.                 JButton button = new JButton("\u6B78\u96F6");
  61.                 button.addActionListener(new ActionListener() {
  62.                         public void actionPerformed(ActionEvent e) {
  63.                                 count=0;
  64.                                 Count.setText(String.valueOf(count));
  65.                         }
  66.                 });
  67.                 button.setBounds(195, 13, 93, 51);
  68.                 contentPane.add(button);
  69.         }
  70. }
複製代碼

TOP

返回列表