JAVA Swing 组件演示***
下面是Swing组件的演示:
package a_swing;import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Cursor; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent;import javax.swing.BoundedRangeModel; import javax.swing.ButtonGroup; import javax.swing.DefaultListModel; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JProgressBar; import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTabbedPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.JTextPane; import javax.swing.JToggleButton; import javax.swing.JTree; import javax.swing.Timer; import javax.swing.border.EtchedBorder; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeSelectionModel;public class Test extends JFrame {public Test() {MenuTest menuTest = new MenuTest();LeftPanel leftPanel = new LeftPanel();RightPanel rightPanel = new RightPanel();BottomPanel bottomPanel = new BottomPanel();CenterPanel centerPanel = new CenterPanel();Container c = this.getContentPane();this.setJMenuBar(menuTest);c.add(leftPanel, BorderLayout.WEST);c.add(rightPanel, BorderLayout.EAST);c.add(centerPanel, BorderLayout.CENTER);c.add(bottomPanel, BorderLayout.SOUTH);this.addWindowListener(new WindowAdapter() {public void WindowClosing(WindowEvent e) {dispose();System.exit(0);}});setSize(700, 500);setTitle("Swing 组件大全简体版");setUndecorated(true);setLocation(200, 150);show();}class MenuTest extends JMenuBar {private JDialog aboutDialog;public MenuTest() {JMenu fileMenu = new JMenu("文件");JMenuItem exitMenuItem = new JMenuItem("退出", KeyEvent.VK_E);JMenuItem aboutMenuItem = new JMenuItem("关于..", KeyEvent.VK_A);fileMenu.add(exitMenuItem);fileMenu.add(aboutMenuItem);this.add(fileMenu);aboutDialog = new JDialog();initAboutDialog();exitMenuItem.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dispose();System.exit(0);}});aboutMenuItem.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {aboutDialog.show();}});}public JDialog get() {return aboutDialog;}public void initAboutDialog() {aboutDialog.setTitle("关于");Container con = aboutDialog.getContentPane();Icon icon = new ImageIcon("sdmile.gif");JLabel aboutLabel = new JLabel("<html><b><font size=5>" + "<center>Swing!" + "<br>", icon, JLabel.CENTER);con.add(aboutLabel, BorderLayout.CENTER);aboutDialog.setSize(450, 225);aboutDialog.setLocation(300, 300);aboutDialog.addWindowListener(new WindowAdapter() {public void WindowClosing(WindowEvent e) {dispose();}});}}class LeftPanel extends JPanel {private int i = 0;public LeftPanel() {DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");DefaultMutableTreeNode select = new DefaultMutableTreeNode("select");DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("" + i);root.add(child);root.add(select);child.add(child1);JTree tree = new JTree(root);tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);tree.setRowHeight(20);tree.addTreeSelectionListener(new TreeSelectionListener() {public void valueChanged(TreeSelectionEvent e) {JTree tree = (JTree) e.getSource();DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();i++;selectNode.add(new DefaultMutableTreeNode("" + i));}});tree.setPreferredSize(new Dimension(100, 300));JScrollPane scrollPane = new JScrollPane(tree);this.add(scrollPane);}}class BottomPanel extends JPanel {private JProgressBar pb;public BottomPanel() {pb = new JProgressBar();pb.setPreferredSize(new Dimension(680, 20));Timer time = new Timer(1, new ActionListener() {int counter = 0;public void actionPerformed(ActionEvent e) {counter++;pb.setValue(counter);Timer t = (Timer) e.getSource();if (counter == pb.getMaximum()) {t.stop();counter = 0;t.start();}}});time.start();pb.setStringPainted(true);pb.setMinimum(0);pb.setMaximum(1000);pb.setBackground(Color.white);pb.setForeground(Color.red);this.add(pb);}public void setProcessBar(BoundedRangeModel rangeModel) {pb.setModel(rangeModel);}}class RightPanel extends JPanel {public RightPanel() {this.setLayout(new GridLayout(8, 1));JCheckBox checkBox = new JCheckBox("复选按钮");JButton button = new JButton("打开文件");button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {JFileChooser file = new JFileChooser();int resule = file.showOpenDialog(new JPanel());if (resule == file.APPROVE_OPTION) {String fileName = file.getSelectedFile().getName();String dir = file.getSelectedFile().getName();JOptionPane.showConfirmDialog(null, dir + "\\" + fileName, "选择的文件", JOptionPane.YES_OPTION);}}});JToggleButton toggleButton = new JToggleButton("双胎按钮");ButtonGroup buttonGroup = new ButtonGroup();JRadioButton radioButton1 = new JRadioButton("单选按钮1", false);JRadioButton radioButton2 = new JRadioButton("单选按钮2", false);JComboBox comboBox = new JComboBox();comboBox.setToolTipText("点击下拉列表增加选项");comboBox.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {JComboBox comboBox = (JComboBox) e.getSource();comboBox.addItem("程序员");comboBox.addItem("分析员");}});DefaultListModel litem = new DefaultListModel();litem.addElement("香蕉");litem.addElement("水果");JList list = new JList(litem);list.addListSelectionListener(new ListSelectionListener() {public void valueChanged(ListSelectionEvent e) {JList l = (JList) e.getSource();Object s = l.getSelectedValue();JOptionPane.showMessageDialog(null, s, "消息框", JOptionPane.YES_OPTION);}});buttonGroup.add(radioButton1);buttonGroup.add(radioButton2);add(button);add(toggleButton);add(checkBox);add(radioButton1);add(radioButton2);add(comboBox);add(list);this.setBorder(new EtchedBorder(EtchedBorder.LOWERED, Color.LIGHT_GRAY, Color.blue));}}class CenterPanel extends JPanel {public CenterPanel() {JTabbedPane tab = new JTabbedPane(JTabbedPane.TOP);JTextField textField = new JTextField("文本域,点击打开<文件按钮>可选择文件");textField.setActionCommand("textField");JTextPane textPane = new JTextPane();textPane.setCursor(new Cursor(Cursor.TEXT_CURSOR));textPane.setText("编辑器,试着点击文本区,试着拉动分隔条。");textPane.addMouseListener(new MouseAdapter() {public void mousePressed(MouseEvent e) {JTextPane textPane = (JTextPane) e.getSource();textPane.setText("编辑器点击命令成功");}});JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, textField, textPane);JTable table = new JTable(10, 10);JPanel pane = new JPanel();pane.add(table.getTableHeader(), BorderLayout.NORTH);pane.add(table);tab.addTab("文本演示", splitPane);tab.addTab("表格演示", pane);tab.setPreferredSize(new Dimension(500, 600));this.add(tab);this.setEnabled(true);}}public static void main(String args[]) {new Test();}}
演示界面如下:
转载于:https://www.cnblogs.com/jiangzhaowei/p/7448582.html
JAVA Swing 组件演示***相关推荐
- java swing 组件技术(上)
2019独角兽企业重金招聘Python工程师标准>>> 第一次写自己的博客,明知道写得很水,还是努力去写了,希望踏出第一步之后,能有着更好的发展.这几天看了一些资料,总结了一下自己所 ...
- java Swing组件总结
文章目录 Jframe JDialog JPanel和JScrollPane容器 文本组件 按钮组件 1.JCheckBox 2.JRadionButton JComboBox组件 菜单组件 1.下拉 ...
- 博为峰Java技术题 ——JavaSE Java Swing组件类的层次
2019独角兽企业重金招聘Python工程师标准>>> 博为峰小博老师: 下图讲述Swing组件类的层次,如图: 从以上的结构示意图中可以知道,Swing组件可以分成两种类型,一种是 ...
- java jpanel调用构造函数的时候就开始执行repaint_在Java Swing组件中劫持`repaint()`调用...
我正在编写一个在无头环境中运行的应用程序,需要输出到Buffered Image而不是屏幕.我有一个管理BufferedImage的Display类.我的应用程序扩展了JPanel,为了在组件更新时自 ...
- java swing 组件渲染过程_Java Swing无法正确渲染
我一直在做一个项目 . 在项目的一部分,我需要在JPanel上绘制 . Graphics2D对象被传递给框架的模型部分,模型将绘制在该实例中绘制的任何内容 . 问题是JFrame未正确呈现 . 它看起 ...
- [Java]Swing窗体演示ZIP压缩流的压缩与解压
最近开始学习java,然后学完了Swing和各种流后,试着写了个ZIP的压缩解压软件出来,具体代码如下: 压缩准备部分: String path = ja.getText();//获取文本域内容Str ...
- java swing组件_Java -- Swing 组件使用
1. 示例1 public class Main { JFrame f = new JFrame(); Icon okIcon = new ImageIcon("/home/test/sta ...
- java背景图片加上组件_关于 java swing组件加背景图片的问题
最近自己做了一个小的进销存软件,背景图片加上后不能最大化.尝试了好几种方法 最后终于把问题解决了.下面把自己写的实例 分享一下: 一个是在JFrame窗体中加如背景图片 一个是在Jpanel 面板中加 ...
- java flowlayout 左对齐_Java Swing组件布局管理器之FlowLayout(流式布局)入门教程
本文实例讲述了Java Swing组件布局管理器之FlowLayout(流式布局).分享给大家供大家参考,具体如下: FlowLayout应该是Swing布局管理器学习中最简单.最基础的一个.所谓流式 ...
最新文章
- 基于 PacBio 测序数据的纠错算法评测与剪切位点识别研究
- PowerDesigner使用教程3
- 简单实用的Windows命令(一)
- OpenCV C++ 10 - Invert Images
- 美国燃油“动脉”被黑客切断,网络安全走向哪里?专访山石网科|拟合
- mysql 查看root_Mysql的Root密码忘记,查看或修改的解决方法(图文介绍)
- 根据一个数字日期,判断这个日期是这一年的第几天
- 无线Wifi模块AP和STA工作模式详解
- chromium禁用ajax,页面加载时,jQuery AJAX不会在Chrome / Chromium中启动
- linux破解卡到抓包,请大家帮帮忙,真的是不会了,本来想做个抓包工具的,结果卡这了...
- 基于ssh框架mysql的jsp系统远吗_JSP+SSH+Mysql实现的学生管理系统
- ReentranLock源码分析
- GoogleMaterialDesign900个实用的Axure图标组件库
- vba 定义类_类接口的实现及应用
- 企业工商信息数据接口说明
- 如何删除电脑上的$RECYCLE.BIN文件夹
- 读《蔡康永的说话之道》
- c语言键盘驱动程序,c语言键盘扫描程序
- webgl径向模糊实现体积光
- 京东一键自动领取京豆、全自动签到、农场浇水、超市兑奖
热门文章
- 数据结构和算法之排序五:选择排序
- Ajax.ActionLink 辅助方法实现局部刷新
- abiword Namespace List
- 磁盘空间管理工具FolderSizes
- matlab中统计工具箱函数名大全
- AUTOSAR从入门到精通100讲(三十四)-AUTOSAR的分层架构
- ajax后台怎么取mapp,后台管理实现
- 计算机一级怎么描述,计算机一级「关于RGB正确的描述的是」相关单选题
- mongodb java id 查询数据_java 用 _id 查找 MongoDB 下的数据
- java json写入内存_如何在客户端上减少JSON.stringify使用的内存量?