Java程序设计教程 冶金工业出版社第5章(4)
JMenuItem fileItem1 = new JMenuItem(\新建三个菜单项 JMenuItem fileItem2 = new JMenuItem(\
JMenuItem fileItem3 = new JMenuItem(\ TabbedPaneOrientation tabbedPane; public SwingDemo() { }
public void init() { }
public void actionPerformed(ActionEvent e) {
//菜单响应事件
//初始函数,为框架添加各种组件 content = getContentPane(); //为菜单添加菜单项 fileMenu.add(fileItem1); fileMenu.add(fileItem2); fileItem1.addActionListener(this); fileItem2.addActionListener(this); fileItem3.addActionListener(this); //将菜单添加到菜单栏 bar.add(fileMenu); setJMenuBar(bar); //添加标签面板
tabbedPane = new TabbedPaneOrientation(); tabbedPane.init(); content.add(tabbedPane);
//构造函数
addWindowListener(new WindowAdapter() { });
public void windowClosing(WindowEvent e) { }
dispose(); System.exit(0);
JMenuItem checkItem = (JMenuItem) e.getSource(); if (checkItem == fileItem1)
fileMenu.insert(fileItem3, 1); System.exit(0); if (checkItem == fileItem2)
}
if (checkItem == fileItem3)
fileMenu.remove(fileItem3);
public static void main(String args[]) { } }
//主函数
System.out.println(\SwingDemo mainFrame = new SwingDemo(); mainFrame.setSize(400, 350); mainFrame.setTitle(\mainFrame.init();
mainFrame.setVisible(true);
//建立一个类扩展自JPanel,其中使用标签面板,并添加组件以及组件的事件处理 class TabbedPaneOrientation extends JPanel implements ActionListener { JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.BOTTOM); JButton button1, button2, button3, button4; public void init() {
//组件初始化
JPanel buttonPanel = new JPanel();
InformationPanel panel1 = new InformationPanel(); SplitPanel panel2 = new SplitPanel(); panel1.init(); panel2.init(); //设置标签面板
tabbedPane.setTabPlacement(JTabbedPane.TOP);
tabbedPane.addTab(\null, panel1, \tabbedPane.addTab(\null, panel2, \button1 = new JButton(\button2 = new JButton(\button3 = new JButton(\button4 = new JButton(\//设置按钮标签 buttonPanel.add(button1); buttonPanel.add(button2); buttonPanel.add(button3); buttonPanel.add(button4); button1.addActionListener(this); button2.addActionListener(this); button3.addActionListener(this);
}
button4.addActionListener(this); button1.setEnabled(false); setLayout(new BorderLayout()); add(tabbedPane, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH);
public void actionPerformed(ActionEvent e) { } }
button1.setEnabled(true); button2.setEnabled(true); button3.setEnabled(true); button4.setEnabled(true); if (e.getSource() == button1) { }
if (e.getSource() == button2) { }
if (e.getSource() == button3) { }
if (e.getSource() == button4) { }
//按钮响应事件
tabbedPane.setTabPlacement(JTabbedPane.TOP); button1.setEnabled(false);
tabbedPane.setTabPlacement(JTabbedPane.LEFT); button2.setEnabled(false);
tabbedPane.setTabPlacement(JTabbedPane.RIGHT); button3.setEnabled(false);
tabbedPane.setTabPlacement(JTabbedPane.BOTTOM); button4.setEnabled(false);
//建立一个类扩展自JSplitPane类,其中分隔显示两个文本字段及一些控制组件 class SplitPanel extends JSplitPane implements ActionListener { JButton buttonA, buttonB;
JTextField text1 = new JTextField(\ JTextField text2 = new JTextField(\ //新建分隔面板
JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, text1, text2); private boolean vertical = true; public void init() {
setLayout(new BorderLayout());
//设置边界布局
}
JPanel buttonPanel = new JPanel(); //新建按钮面板
buttonA = new JButton(\buttonA.addActionListener(this); buttonPanel.add(buttonA);
buttonB = new JButton(\buttonB.addActionListener(this); buttonPanel.add(buttonB);
add(split, BorderLayout.CENTER);
//添加分隔面板 //添加按钮面板
add(buttonPanel, BorderLayout.SOUTH);
public void actionPerformed(ActionEvent e) { } }
if (e.getSource() == buttonA) { }
if (e.getSource() == buttonB) { }
if (vertical) { }
if (split.isOneTouchExpandable()) { }
//按钮响应事件
split.setOneTouchExpandable(false);
buttonA.setText(\split.setOneTouchExpandable(true); buttonA.setText(\
} else {
split.setOrientation(JSplitPane.HORIZONTAL_SPLIT); buttonB.setText(\vertical = false;
split.setOrientation(JSplitPane.VERTICAL_SPLIT); buttonB.setText(\vertical = true;
} else {
//建立一个信息选择面板类扩展自JPanel,其中添加多种控制组件 class InformationPanel extends JPanel implements ActionListener { JLabel label;
JTextField name = new JTextField(8);
JPasswordField password = new JPasswordField(8); ButtonGroup bg = new ButtonGroup();
String[] elements = {\
\
JCheckBox gym, music, computer; JList skill;
JButton summit, cancel; JComboBox diploma; JRadioButton male, female; public void init() {
//组件初始化
GridBagLayout gridbag = new GridBagLayout(); //新建网格包布局管理器 GridBagConstraints constraints = new GridBagConstraints();//新建网格包限制 setLayout(gridbag);
//新建“Name”标签并设置属性 label = new JLabel(\
constraints.fill = GridBagConstraints.BOTH; constraints.gridy = 0; constraints.weightx = 0.5;
gridbag.setConstraints(label, constraints); add(label);
constraints.gridx = 1;
gridbag.setConstraints(name, constraints); add(name);
//新建“Password”标签并设置属性 label = new JLabel(\constraints.gridx = 2 …… 此处隐藏:3157字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [法律文档]苏教版七年级语文下册第五单元教学设计
- [法律文档]向市委巡视组进点汇报材料
- [法律文档]绵阳市2018年高三物理上学期第二次月考
- [法律文档]浅析如何解决当代中国“新三座大山”的
- [法律文档]延安北过境线大桥工程防洪评价报告 -
- [法律文档]激活生成元素让数学课堂充满生机
- [法律文档]2014年春学期九年级5月教学质量检测语
- [法律文档]放射科标准及各项计1
- [法律文档]2012年广州化学中考试题和答案(原版)
- [法律文档]地球物理勘查规范
- [法律文档]《12系列建筑标准设计图集》目录
- [法律文档]2018年宁波市专技人员继续教育公需课-
- [法律文档]工会委员会工作职责
- [法律文档]2014新版外研社九年级英语上册课文(完
- [法律文档]《阅微草堂笔记》部分篇目赏析
- [法律文档]尔雅军事理论2018课后答案(南开版)
- [法律文档]储竣-13827 黑娃山沟大开挖穿越说明书
- [法律文档]《产品设计》教学大纲及课程简介
- [法律文档]电动吊篮专项施工方案 - 图文
- [法律文档]实木地板和复合地板的比较
- 探析如何提高电力系统中PLC的可靠性
- 用Excel函数快速实现体能测试成绩统计
- 教师招聘考试重点分析:班主任工作常识
- 高三历史选修一《历史上重大改革回眸》
- 2013年中山市部分职位(工种)人力资源视
- 2015年中国水溶性蛋白市场年度调研报告
- 原地踏步走与立定教学设计
- 何家弘法律英语课件_第十二课
- 海信冰箱经销商大会——齐俊强副总经理
- 犯罪心理学讲座
- 初中英语作文病句和错句修改范例
- 虚拟化群集部署计划及操作流程
- 焊接板式塔顶冷凝器设计
- 浅析语文教学中
- 结构力学——6位移法
- 天正建筑CAD制图技巧
- 中华人民共和国财政部令第57号——注册
- 赢在企业文化展厅设计的起跑线上
- 2013版物理一轮精品复习学案:实验6
- 直隶总督署简介




