嵌套的面板

来源:互联网 发布:java语言的特点是什么 编辑:程序博客网 时间:2024/06/15 17:04
//**********************************************//  NestedPanels.java    Author: Lewis/Loftus//**********************************************import java.awt.*;import javax.swing.*;public class NestedPanels{//---------------------------------------------------// Prestents two colored panels nested with a third//---------------------------------------------------public static void main(String[] args){JFrame frame = new JFrame("Nested Panels");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// Set up first subpanelJPanel subPanel1 = new JPanel();subPanel1.setPreferredSize(new Dimension(150,100));subPanel1.setBackground(Color.green);JLabel label1 = new JLabel("One");subPanel1.add(label1);// Set up second subpanelJPanel subPanel2 = new JPanel();subPanel2.setPreferredSize(new Dimension(150,100));subPanel2.setBackground(Color.red);JLabel label2 = new JLabel("Two");subPanel2.add(label2);// Set up primary panelJPanel primary = new JPanel();primary.setBackground(Color.blue);primary.add(subPanel1);primary.add(subPanel2);frame.getContentPane().add(primary);frame.pack();frame.setVisible(true);}}

原创粉丝点击