- package bbs.istak.org.tw;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.GroupLayout;
- import javax.swing.GroupLayout.Alignment;
- import javax.swing.JLabel;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class Main extends JFrame {
- private JPanel contentPane;
- private int count =0;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Main frame = new Main();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public Main() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 326, 171);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
-
- JLabel lblNewLabel = new JLabel("0");
- lblNewLabel.setBounds(10, 10, 98, 100);
- contentPane.add(lblNewLabel);
-
- JButton btnNewButton = new JButton("\u9EDE\u64CA");
- btnNewButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- lblNewLabel.setText(String.valueOf(++count));
- }
- });
- btnNewButton.setBounds(118, 49, 87, 23);
- contentPane.add(btnNewButton);
-
- JButton btnNewButton_1 = new JButton("\u6B78\u96F6");
- btnNewButton_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- lblNewLabel.setText("0");
- count = 0;
- }
- });
- btnNewButton_1.setBounds(213, 49, 87, 23);
- contentPane.add(btnNewButton_1);
- }
- }
複製代碼 |