📄 multibuttons.java
字号:
import javax.swing.*;
import java.awt.event.*;
import java.awt.Container; // need this to add controls
import java.awt.*; // need this for layout manager
public class MultiButtons extends JFrame
{
private JFrame mainFrame;
private JButton messageButton;
private JButton clearButton;
private JButton exitButton;
public MultiButtons() // a constructor
{
mainFrame = new JFrame("The Hello Application - Ver. 1.0");
// create the button objects
messageButton = new JButton("Message");
clearButton = new JButton("Clear");
exitButton = new JButton("Exit");
// get the content pane & specify layout manager
Container c = mainFrame.getContentPane();
c.setLayout(new FlowLayout());
// add the button to the ContentPane
c.add(messageButton);
c.add(clearButton);
c.add(exitButton);
// create accelerator keys
messageButton.setMnemonic('M');
clearButton.setMnemonic('C');
exitButton.setMnemonic('x');
mainFrame.setSize(300,100);
// define and register window event handler
mainFrame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e) {System.exit(0);}
});
mainFrame.show();
}
public static void main(String args[])
{
MultiButtons app = new MultiButtons(); // instantiate a GUI object
}
} // end of class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -