testpanels.java

来自「java课件」· Java 代码 · 共 56 行

JAVA
56
字号
/*
 * TestPanels.java
 *
 * Created on 2007年10月20日, 下午11:16
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
import java.awt.*;
import javax.swing.*;
/**
 *
 * @author admin
 */
public class TestPanels extends JFrame{
  
  /** Creates a new instance of TestPanels */
  public TestPanels() {
    //Get the content pane of the frame
    Container container = this.getContentPane();
    
    //set BorderLayout for the frame
    container.setLayout(new BorderLayout());
    
    //create panel p1 for the buttons and set GridLayout
    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(4,3));
    
    //add buttons to the panel
    for (int i = 1; i <=9; i++) {
      p1.add(new JButton(""+i));
    }
    p1.add(new JButton("0"));
    p1.add(new JButton("start"));
    p1.add(new JButton("stop"));
    
    //create panel p2 to hold a text field and p1
    JPanel p2 = new JPanel(new BorderLayout());
    p2.add(new JTextField("Time to be displayed here"), BorderLayout.NORTH);
    p2.add(p1, BorderLayout.CENTER);
    
    //add p2 and a button to the frame
    container.add(p2, BorderLayout.EAST);
    container.add(new JButton("Food to be placed here"), BorderLayout.CENTER);
  }

  public static void main(String[] args) {
    TestPanels frame = new TestPanels();
    
    frame.setTitle("The front view of a microwave oven");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 250);
    frame.setVisible(true);
  }
}

⌨️ 快捷键说明

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