77范文网 - 专业文章范例文档资料分享平台

Java程序设计教程 冶金工业出版社第5章(4)

来源:网络收集 时间:2019-08-17 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

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;

gridbag.setConstraints(label, constraints); add(label);

constraints.gridx = 3;

gridbag.setConstraints(password, constraints); add(password);

//新建“ComboBox”并设置属性

diploma = new JComboBox(new Object[]{\

\

constraints.gridx = 0; constraints.gridy = 1; constraints.gridwidth = 2;

gridbag.setConstraints(diploma, constraints);

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库Java程序设计教程 冶金工业出版社第5章(4)在线全文阅读。

Java程序设计教程 冶金工业出版社第5章(4).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/jiaoyu/681064.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: