Java复杂GUI布局举例与源码
2013-08-23 15:06
267 查看
【举例要求】要求完成下图中要求的布局,形式要求一致,并且要求美观。这里使用的布局较多,比较复杂,编写好的源码与大家分享一下。
package ComPlexPanel;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
public class ComPlexPanel {
JFrame frame = new JFrame("ComPlexPanelDemo Made
By HY49");
Container content = frame.getContentPane();
public ComPlexPanel(){
JPanel GrandParentPanel = new
JPanel();
// JPanel FatherPanel = new
JPanel();
JPanel MotherPanel = new
JPanel(new GridLayout(4,1));
JPanel BrotherPanel01 = new
JPanel();
JPanel BrotherPanel02 = new
JPanel(new GridLayout(1,5));
JPanel BrotherPanel03 = new
JPanel();
JPanel SonPanel01 = new
JPanel();
JTextArea area01 = new
JTextArea(6,5);
SonPanel01.add(area01);
JPanel SonPanel02 = new
JPanel(new GridLayout(3,1));
JPanel SonPanel03 = new
JPanel();
JTextArea area02 = new
JTextArea(6,5);
SonPanel03.add(area02);
JPanel SonPanel04 = new
JPanel(new GridLayout(3,1));
JPanel SonPanel05 = new
JPanel();
JTextArea area03 = new
JTextArea(6,5);
SonPanel05.add(area03);
JButton OKButton = new
JButton("OK");
JButton CancleButton = new
JButton("Cancle");
JButton SetupButton = new
JButton("SetUp");
JButton HelpButton = new
JButton("Help");
MotherPanel.add(OKButton);
MotherPanel.add(CancleButton);
MotherPanel.add(SetupButton);
MotherPanel.add(HelpButton);
JLabel label01= new
JLabel("Demo: ComPlexPanelDemo",JLabel.CENTER);
BrotherPanel01.add(label01);
JLabel label02 = new
JLabel("Priority: ");
String[] Priority =
{"High","Middle","Low"};
JComboBox comboBox = new
JComboBox(Priority);
comboBox.setEditable(false);
comboBox.setSelectedItem("High");
JCheckBox checkBox = new
JCheckBox("Print to File");
BrotherPanel03.add(label02);
BrotherPanel03.add(comboBox);
BrotherPanel03.add(checkBox);
JCheckBox checkBox01 = new
JCheckBox("Image");
JCheckBox checkBox02 = new
JCheckBox("Text");
JCheckBox checkBox03 = new
JCheckBox("Code");
SonPanel02.add(checkBox01);
SonPanel02.add(checkBox02);
SonPanel02.add(checkBox03);
ButtonGroup buttonGroup = new
ButtonGroup();
JRadioButton radioButton01 =
new JRadioButton("Selection");
buttonGroup.add(radioButton01);
JRadioButton radioButton02 =
new JRadioButton("All");
radioButton02.setSelected(true);
buttonGroup.add(radioButton02);
JRadioButton radioButton03 =
new JRadioButton("Applet");
buttonGroup.add(radioButton03);
SonPanel04.add(radioButton01);
SonPanel04.add(radioButton02);
SonPanel04.add(radioButton03);
SonPanel04.setSize(30,
50);
BrotherPanel02.add(SonPanel01);
BrotherPanel02.add(SonPanel02);
BrotherPanel02.add(SonPanel03);
BrotherPanel02.add(SonPanel04);
BrotherPanel02.add(SonPanel05);
GrandParentPanel.add(BrotherPanel01,BorderLayout.NORTH);
GrandParentPanel.add(BrotherPanel02,BorderLayout.CENTER);
GrandParentPanel.add(MotherPanel,BorderLayout.EAST);
GrandParentPanel.add(BrotherPanel03,BorderLayout.SOUTH);
content.add(GrandParentPanel);
frame.setVisible(true);
frame.setBounds(450, 200, 490,
260);
// frame.pack();
}
public static void main(String[] args) {
// TODO Auto-generated method
stub
new ComPlexPanel();
}
}
package ComPlexPanel;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
public class ComPlexPanel {
JFrame frame = new JFrame("ComPlexPanelDemo Made
By HY49");
Container content = frame.getContentPane();
public ComPlexPanel(){
JPanel GrandParentPanel = new
JPanel();
// JPanel FatherPanel = new
JPanel();
JPanel MotherPanel = new
JPanel(new GridLayout(4,1));
JPanel BrotherPanel01 = new
JPanel();
JPanel BrotherPanel02 = new
JPanel(new GridLayout(1,5));
JPanel BrotherPanel03 = new
JPanel();
JPanel SonPanel01 = new
JPanel();
JTextArea area01 = new
JTextArea(6,5);
SonPanel01.add(area01);
JPanel SonPanel02 = new
JPanel(new GridLayout(3,1));
JPanel SonPanel03 = new
JPanel();
JTextArea area02 = new
JTextArea(6,5);
SonPanel03.add(area02);
JPanel SonPanel04 = new
JPanel(new GridLayout(3,1));
JPanel SonPanel05 = new
JPanel();
JTextArea area03 = new
JTextArea(6,5);
SonPanel05.add(area03);
JButton OKButton = new
JButton("OK");
JButton CancleButton = new
JButton("Cancle");
JButton SetupButton = new
JButton("SetUp");
JButton HelpButton = new
JButton("Help");
MotherPanel.add(OKButton);
MotherPanel.add(CancleButton);
MotherPanel.add(SetupButton);
MotherPanel.add(HelpButton);
JLabel label01= new
JLabel("Demo: ComPlexPanelDemo",JLabel.CENTER);
BrotherPanel01.add(label01);
JLabel label02 = new
JLabel("Priority: ");
String[] Priority =
{"High","Middle","Low"};
JComboBox comboBox = new
JComboBox(Priority);
comboBox.setEditable(false);
comboBox.setSelectedItem("High");
JCheckBox checkBox = new
JCheckBox("Print to File");
BrotherPanel03.add(label02);
BrotherPanel03.add(comboBox);
BrotherPanel03.add(checkBox);
JCheckBox checkBox01 = new
JCheckBox("Image");
JCheckBox checkBox02 = new
JCheckBox("Text");
JCheckBox checkBox03 = new
JCheckBox("Code");
SonPanel02.add(checkBox01);
SonPanel02.add(checkBox02);
SonPanel02.add(checkBox03);
ButtonGroup buttonGroup = new
ButtonGroup();
JRadioButton radioButton01 =
new JRadioButton("Selection");
buttonGroup.add(radioButton01);
JRadioButton radioButton02 =
new JRadioButton("All");
radioButton02.setSelected(true);
buttonGroup.add(radioButton02);
JRadioButton radioButton03 =
new JRadioButton("Applet");
buttonGroup.add(radioButton03);
SonPanel04.add(radioButton01);
SonPanel04.add(radioButton02);
SonPanel04.add(radioButton03);
SonPanel04.setSize(30,
50);
BrotherPanel02.add(SonPanel01);
BrotherPanel02.add(SonPanel02);
BrotherPanel02.add(SonPanel03);
BrotherPanel02.add(SonPanel04);
BrotherPanel02.add(SonPanel05);
GrandParentPanel.add(BrotherPanel01,BorderLayout.NORTH);
GrandParentPanel.add(BrotherPanel02,BorderLayout.CENTER);
GrandParentPanel.add(MotherPanel,BorderLayout.EAST);
GrandParentPanel.add(BrotherPanel03,BorderLayout.SOUTH);
content.add(GrandParentPanel);
frame.setVisible(true);
frame.setBounds(450, 200, 490,
260);
// frame.pack();
}
public static void main(String[] args) {
// TODO Auto-generated method
stub
new ComPlexPanel();
}
}
相关文章推荐
- Java的GUI组件的布局管理器
- java -- GUI程序设计之无布局管理器布局
- 安卓复杂滑动案例 自定义behavior源码分析 实现头布局图片的缩放透明度变化,RecycleView的滑动布局,坐标变化
- 自己写的一个简单的Java GUI源码
- atitit.软件开发GUI 布局管理优缺点总结java swing wpf web html c++ qt php asp.net winform
- Java_GUI_布局_箱式布局
- java学习之 论GUI中JPanel的布局设置问题
- Java基础--Java---IO流------GUI(布局)、Frame、事件监听机制、窗体事件、Action事件、鼠标事件、对话框Dialog、键盘事件、菜单
- 安卓复杂滑动案例 自定义behavior源码分析 实现头布局图片的缩放透明度变化,RecycleView的滑动布局,坐标变化
- JAVA之旅(三十一)——JAVA的图形化界面,GUI布局,Frame,GUI事件监听机制,Action事件,鼠标事件
- JAVA基础再回首(二十七)——JAVA中的图形化界面、GUI概述、简单的窗体创建、事件监听机制、动作事件、GUI布局、鼠标事件
- JAVA图形界面(GUI)之布局管理器
- Java基础-GUI(概述、布局、Frame、事件监听机制等事件演示)
- Java GUI之五大布局
- atitit.软件开发GUI 布局管理优缺点总结java swing wpf web html c++ qt php asp.net winform
- JAVA之旅(三十一)——JAVA的图形化界面,GUI布局,Frame,GUI事件监听机制,Action事件,鼠标事件
- JAVA反射包应用功能GUI程序举例
- Java_GUI_布局_流式布局
- JAVA进行GUI程序设计之布局管理(下)
- java下简单GUI布局与监听