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

📄 ch4_4panel.java

📁 里面所含源码是本人平时做程序的一些实例
💻 JAVA
字号:
import javax.swing.*;
import java.awt.*;
public class ch4_4Panel extends JFrame{
	Container 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));//网格布局方式
		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 + -