⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jbuttondemo.java

📁 ssd3的教程 是我们老师给我们的 纯英文 有兴趣的可以
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;

/**
 * Demonstrates the component {@link JButton}. This class extends
 * class {@link @JPanel}.
 *
 * @author author name
 * @version 1.0.0
 */
public class JButtonDemo extends JPanel {

    private JButton buttonUp;
    private JButton buttonDown;
    private ImageIcon arrowUp;
    private ImageIcon arrowDown;

    /**
     * Creates a window.
     *
     * @param args  not used.
     */
    public static void main(String[] args) {

        JFrame frame = new JFrame("JButtonDemo");

        frame.setContentPane(new JButtonDemo());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();    // Adjust the size of the window
        frame.setVisible(true);
    }

    /**
     * Creates two {@link JButton} components.
     */
    public JButtonDemo() {

        setLayout(new GridLayout(2, 1));
        setBackground(Color.white);

        arrowUp = new ImageIcon("images/up.gif",
                                "up arrow");
        arrowDown= new ImageIcon("images/down.gif",
                                 "down arrow");

        // Create the components
        buttonUp = new JButton("Up", arrowUp);
        buttonDown = new JButton("Down", arrowDown);

        // Set the position of the text, relative to the icon
        buttonUp.setVerticalTextPosition(AbstractButton.CENTER);
        buttonUp.setHorizontalTextPosition(AbstractButton.LEFT);
        buttonDown.setVerticalTextPosition(AbstractButton.CENTER);
        buttonDown.setHorizontalTextPosition(AbstractButton.LEFT);

        // Set the color of buttons
        buttonUp.setBackground(new Color(0, 100, 0));
        buttonDown.setBackground(new Color(0, 100, 0));
        buttonUp.setForeground(Color.white);
        buttonDown.setForeground(Color.white);

        // Disable the Down button
        buttonDown.setEnabled(false);

        // Add buttons to the container
        add(buttonUp);
        add(buttonDown);
    }
}

⌨️ 快捷键说明

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