?? ch4_4.java
字號:
import javax.swing.*;
import java.awt.*;
public class ch4_4Panel extends JFrame{
JPanel pnlMain;
public ch4_4Panel(){
pnlMain=new JPanel(new GridLayout(2,1));
TopPanel tPanel=new TopPanel();
BottomPanel bPanel=new BottomPanel();
this.setContentPane(pnlMain);
//this.getContentPane().add(pnlMain);
pnlMain.add(tPanel);
pnlMain.add(bPanel);
setTitle("Panel程序演示");
setSize(250,150);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String args[]){
new ch4_4Panel();
}
}
class TopPanel extends JPanel{
JLabel lblWelcome;
JLabel lblTop;
public TopPanel(){
lblWelcome=new JLabel("歡迎進入JAVA世界!");
lblTop=new JLabel("上部面板");
setLayout(new GridLayout(2,1));//網(wǎng)格布局方式
add(lblWelcome);
add(lblTop);
}
}
class BottomPanel extends JPanel{
JLabel lblBottom;
JButton btnExit;
public BottomPanel(){
// 默認為流布局方式
lblBottom=new JLabel("下部面板");
btnExit=new JButton("點擊退出");
add(lblBottom);
add(btnExit);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -