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

📄 defaultbuttonexample.java

📁 java swing 开发代码
💻 JAVA
字号:
// DefaultButtonExample.java// Example using defaultButton and JRootPane.setDefaultButton()//package	jswing.ch05;import javax.swing.*;import java.awt.*;public class DefaultButtonExample {  public static void main(String[] args) {    // Create some buttons    JButton ok = new JButton("OK");    JButton cancel = new JButton("Cancel");    JPanel buttonPanel = new JPanel();    buttonPanel.add(ok);    buttonPanel.add(cancel);    JLabel msg = new JLabel("Is this OK?", JLabel.CENTER);    // Create a frame, get its root pane, and set the OK button as the    // default. This button is pressed if we press the Enter key while the    // frame has focus.    JFrame f = new JFrame();    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    JRootPane root = f.getRootPane();    root.setDefaultButton(ok);    // Layout and Display    Container content = f.getContentPane();    content.setLayout(new BorderLayout());    content.add(msg, BorderLayout.CENTER);    content.add(buttonPanel, BorderLayout.SOUTH);    f.setSize(200,100);    f.setVisible(true);  }}

⌨️ 快捷键说明

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