📄 buttonguitwo.java
字号:
import javax.swing.*;
import java.awt.event.*;
import java.awt.Container; // need this to add controls
public class ButtonGuiTwo extends JFrame
{
private JFrame mainFrame;
private JButton firstButton; // Step 1 - first statement
public ButtonGuiTwo() // a constructor
{
mainFrame = new JFrame("Example of a Gui with a Button");
// create a button object
firstButton = new JButton("Press me"); // Step 1 - second statement
// get the content pane
Container c = mainFrame.getContentPane(); // Step 2 - first statement
// add the button to the ContentPane
c.add(firstButton); // Step 2 - second statement
firstButton.setToolTipText("This is a button"); // create a ToolTip
firstButton.setMnemonic('P'); // create a mnemonic key
mainFrame.setSize(300,150);
// 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[])
{
new ButtonGuiTwo(); // instantiate a GUI object
}
} // end of ButtonGuiTwo class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -