- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.awt.Font;
- import javax.swing.JTextArea;
- import javax.swing.JTextPane;
- import javax.swing.JTextField;
- public class Click extends JFrame {
- private JPanel contentPane;
- private JTextField tf1;
- public int click=0;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
-
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Click frame = new Click();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public Click() {
- setTitle("\u9EDE\u64CA\u8A08\u6578\u5668");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 364, 93);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
-
- JButton btn2 = new JButton("\u6B78\u96F6");
- btn2.setFont(new Font("微軟正黑體", Font.PLAIN, 14));
- btn2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0)
- {
- click=0;
- tf1.setText(String.valueOf(click));
- }
- });
- btn2.setBounds(250, 14, 88, 32);
- contentPane.add(btn2);
-
- JButton btn1 = new JButton("\u9EDE\u64CA");
- btn1.setFont(new Font("微軟正黑體", Font.PLAIN, 16));
- btn1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
- click++;
- tf1.setText(String.valueOf(click));
- }
- });
- btn1.setBounds(152, 13, 88, 32);
- contentPane.add(btn1);
-
- tf1 = new JTextField();
- tf1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
- tf1.setText(String.valueOf(click));
- }
- });
- tf1.setFont(new Font("Consolas", Font.PLAIN, 14));
- tf1.setBounds(10, 14, 132, 28);
- contentPane.add(tf1);
- tf1.setColumns(10);
- }
- }
複製代碼 |