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

📄 buttonguitwo.java

📁 《A first book of java》by Gary J.Bronson 北大出版社
💻 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 + -