第二次作业
2016-03-18 22:11
337 查看
这次作业学会运用单选框、复选框还有添加事件的响应,在做这次作业的时候感觉不太会界面布局,让界面不太美观。
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
public class X {
JFrame frame = new JFrame("购票系统");
Container content = frame.getContentPane();
public X(){
JPanel GrandParentPanel = new JPanel( );
JPanel MotherPanel = new JPanel(new FlowLayout());
JPanel BrotherJPanel01 = new JPanel();
JPanel BrotherJPanel02 = new JPanel(new FlowLayout());
JPanel BrotherJPanel03 = new JPanel();
JPanel SonPanel01 = new JPanel();
JTextArea area01 = new JTextArea("购票人群");
SonPanel01.add(area01);
JPanel SonPanel02 = new JPanel(new FlowLayout());
JPanel SonPanel03 = new JPanel();
JTextArea area02 = new JTextArea("支付方式");
SonPanel03.add(area02);
JPanel SonPanel04 = new JPanel(new FlowLayout());
JPanel SonPanel05 = new JPanel();
JTextArea area03 = new JTextArea("票类");
SonPanel05.add(area03);
JButton btn1 = new JButton("银行卡");
JButton btn2 = new JButton("现金");
JButton btn3 = new JButton("支付宝");
JButton btn4 = new JButton("微信");
MotherPanel.add(btn1);
MotherPanel.add(btn2);
MotherPanel.add(btn3);
MotherPanel.add(btn4);
JCheckBox checkBox01 = new JCheckBox("成人票");
JCheckBox checkBox02 = new JCheckBox("儿童票");
JCheckBox checkBox03 = new JCheckBox("学生票");
SonPanel02.add(checkBox01);
SonPanel02.add(checkBox02);
SonPanel02.add(checkBox03);
ButtonGroup buttonGroup = new ButtonGroup();
JRadioButton radioButton01= new JRadioButton("开车前两小时");
buttonGroup.add(radioButton01);
JRadioButton radioButton02= new JRadioButton("一周之内开车");
buttonGroup.add(radioButton02);
JRadioButton radioButton03= new JRadioButton("两月之内开车");
buttonGroup.add(radioButton03);
SonPanel04.add(radioButton01);
SonPanel04.add(radioButton02);
SonPanel04.add(radioButton03);
SonPanel04.setSize(30,50);
BrotherJPanel02 .add(SonPanel01);
BrotherJPanel02 .add(SonPanel02);
BrotherJPanel02 .add(SonPanel03);
BrotherJPanel02 .add(SonPanel04);
BrotherJPanel02 .add(SonPanel05);
GrandParentPanel.add(BrotherJPanel01 );
GrandParentPanel.add(BrotherJPanel02 );
GrandParentPanel.add(MotherPanel );
GrandParentPanel.add(BrotherJPanel03 );
content.add(GrandParentPanel);
frame.setVisible(true);
frame.setBounds(850, 200, 490,260);
btn1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
JFrame frame1 = new JFrame("购票系统");
JLabel label =new JLabel("您选择了银行卡");
frame1.add(label);
frame1.setVisible(true);
frame1.setBounds(850, 200, 490,260);
}
});
}
public static void main(String[] args){
new X();
}
}
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
public class X {
JFrame frame = new JFrame("购票系统");
Container content = frame.getContentPane();
public X(){
JPanel GrandParentPanel = new JPanel( );
JPanel MotherPanel = new JPanel(new FlowLayout());
JPanel BrotherJPanel01 = new JPanel();
JPanel BrotherJPanel02 = new JPanel(new FlowLayout());
JPanel BrotherJPanel03 = new JPanel();
JPanel SonPanel01 = new JPanel();
JTextArea area01 = new JTextArea("购票人群");
SonPanel01.add(area01);
JPanel SonPanel02 = new JPanel(new FlowLayout());
JPanel SonPanel03 = new JPanel();
JTextArea area02 = new JTextArea("支付方式");
SonPanel03.add(area02);
JPanel SonPanel04 = new JPanel(new FlowLayout());
JPanel SonPanel05 = new JPanel();
JTextArea area03 = new JTextArea("票类");
SonPanel05.add(area03);
JButton btn1 = new JButton("银行卡");
JButton btn2 = new JButton("现金");
JButton btn3 = new JButton("支付宝");
JButton btn4 = new JButton("微信");
MotherPanel.add(btn1);
MotherPanel.add(btn2);
MotherPanel.add(btn3);
MotherPanel.add(btn4);
JCheckBox checkBox01 = new JCheckBox("成人票");
JCheckBox checkBox02 = new JCheckBox("儿童票");
JCheckBox checkBox03 = new JCheckBox("学生票");
SonPanel02.add(checkBox01);
SonPanel02.add(checkBox02);
SonPanel02.add(checkBox03);
ButtonGroup buttonGroup = new ButtonGroup();
JRadioButton radioButton01= new JRadioButton("开车前两小时");
buttonGroup.add(radioButton01);
JRadioButton radioButton02= new JRadioButton("一周之内开车");
buttonGroup.add(radioButton02);
JRadioButton radioButton03= new JRadioButton("两月之内开车");
buttonGroup.add(radioButton03);
SonPanel04.add(radioButton01);
SonPanel04.add(radioButton02);
SonPanel04.add(radioButton03);
SonPanel04.setSize(30,50);
BrotherJPanel02 .add(SonPanel01);
BrotherJPanel02 .add(SonPanel02);
BrotherJPanel02 .add(SonPanel03);
BrotherJPanel02 .add(SonPanel04);
BrotherJPanel02 .add(SonPanel05);
GrandParentPanel.add(BrotherJPanel01 );
GrandParentPanel.add(BrotherJPanel02 );
GrandParentPanel.add(MotherPanel );
GrandParentPanel.add(BrotherJPanel03 );
content.add(GrandParentPanel);
frame.setVisible(true);
frame.setBounds(850, 200, 490,260);
btn1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
JFrame frame1 = new JFrame("购票系统");
JLabel label =new JLabel("您选择了银行卡");
frame1.add(label);
frame1.setVisible(true);
frame1.setBounds(850, 200, 490,260);
}
});
}
public static void main(String[] args){
new X();
}
}
相关文章推荐
- 【转】Oracle和DB2术语对照表
- 发送短信验证码按钮的实现
- 反思——针对作业的反思
- 关于索引的sql语句优化之降龙十八掌
- LINQ找出重复和不重复的元素及linq OrderBy 方法 两个字段同时排序有关问题
- hdu1358 Period--KMP
- 软考信息系统监理师,2016年3月18日作业
- Flume+Kafka+Storm的实时日志统计
- 继承,菱形继承,多态,虚拟继承,多虚拟继承,菱形虚拟继承
- [疯狂Java]多线程:线程组、线程/组内异常处理
- 求二叉树的深度
- 浅析Delphi Container库(有开源的DCLX)
- 构建之法阅读笔记02
- 在中国,程序员的职业生涯有多长?
- dbvisualizer中文乱码
- 关于abstract使用正确的一个经典选择题
- XML-RPC远程方法调用
- 按照CRUD的原则整理一下git基本命令
- CCPP资料
- java(jsp)简单实现数据库学生信息的增删改查案例