buttondemo.java

来自「That is some example about GUI. It is ve」· Java 代码 · 共 35 行

JAVA
35
字号

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ButtonDemo extends JFrame implements ActionListener {

    private JButton button;
    private JTextField textField;

    public static void main(String[] args) {
        ButtonDemo frame = new ButtonDemo();
        frame.setSize(400,300);
        frame.createGUI();
        frame.show();
    }

    private void createGUI() {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        Container window = getContentPane();
        window.setLayout(new FlowLayout());

        button = new JButton("Press me");
        window.add(button);
        button.addActionListener(this);

        textField = new JTextField(10);
        window.add(textField);
    }

    public void actionPerformed(ActionEvent event) {
        textField.setText("button clicked");
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?