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

📄 chap11-2.txt

📁 清华大学出版社经典教材系列
💻 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( );// 获取框架的内容格
        
        JPanel   jp1=new JPanel( );       		// 定义一个面板
        fillComponent(jp1);             		// 向面板添加组件
        jp1.setBackground(Color.BLUE);  		// 设置面板的背景色
        jp1.setForeground(Color.ORANGE); 	// 设置面板的前景色
        
        JPanel   jp2=new JPanel( );       		// 定义一个面板
        fillComponent(jp2);             		// 向面板添加组件
        jp2.setBackground(Color.GRAY);  		// 设置面板的背景色
        jp2.setForeground(Color.BLACK); 		// 设置面板的前景色 
        
        contentPane.add(jp1,BorderLayout.NORTH); 	// 将面板jp1放在内容格的北边
        contentPane.add(jp2,BorderLayout.SOUTH);  	// 将面板jp2放在内容格的南边 
        
        frame.setSize(200,100);
        frame.show( );
    }

    public static void main(String args[ ]){
        testJPanel  obj=new testJPanel( );
    }
}

⌨️ 快捷键说明

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