?? chap11-2.txt
字號:
// 程序11-2
import java.awt.*;
import javax.swing.*;
public class testJPanel{
private void fillComponent(Container c){
for(int i=0;i<3;i++)
c.add(new JButton(""+i));
}
public testJPanel( ){
JFrame frame=new subJFrame("testJPanel"); // 定義一個框架
Container contentPane=frame.getContentPane( );// 獲取框架的內(nèi)容格
JPanel jp1=new JPanel( ); // 定義一個面板
fillComponent(jp1); // 向面板添加組件
jp1.setBackground(Color.BLUE); // 設(shè)置面板的背景色
jp1.setForeground(Color.ORANGE); // 設(shè)置面板的前景色
JPanel jp2=new JPanel( ); // 定義一個面板
fillComponent(jp2); // 向面板添加組件
jp2.setBackground(Color.GRAY); // 設(shè)置面板的背景色
jp2.setForeground(Color.BLACK); // 設(shè)置面板的前景色
contentPane.add(jp1,BorderLayout.NORTH); // 將面板jp1放在內(nèi)容格的北邊
contentPane.add(jp2,BorderLayout.SOUTH); // 將面板jp2放在內(nèi)容格的南邊
frame.setSize(200,100);
frame.show( );
}
public static void main(String args[ ]){
testJPanel obj=new testJPanel( );
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -