textguione.java

来自「《A first book of java》by Gary J.Bronson 」· Java 代码 · 共 45 行

JAVA
45
字号
public class TextGuiOne extends JFrame
{
  private JFrame mainFrame;
  private JButton messageButton;
  private JButton clearButton;
  private JButton exitButton;
  private JTextField tField;
 
  public TextGuiOne() // a constructor
  {
    mainFrame = new JFrame("The Hello Application-Ver.2.0");
      // create all components
    messageButton = new JButton("Message");  
    clearButton = new JButton("Clear");
    exitButton = new JButton("Exit");
    tField = new JTextField("Hello World!");
      // get the content pane 
    Container c = mainFrame.getContentPane(); // Step 2 - first statement
    
      // add the components to the ContentPane 
    c.add(tfield,BorderLayout.NORTH);
    c.add(messageButton,BorderLayout.WEST);
    c.add(clearButton,BorderLayout.CENTER);
    c.add(exitButton,BorderLayout.EAST);
    
      // create accelerator keys
    messageButton.setMnemonic('M');
    clearButton.setMnemonic('C');
    exitButton.setMnemonic('x');
    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 TextGuiOne();  // instantiate a GUI object 
  }
}  // end of class

⌨️ 快捷键说明

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