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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/371381.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Spring 3.1缓存和@CacheEvict

我的上一个博客演示了Spring 3.1的Cacheable批注的应用&#xff0c; Cacheable批注用于标记返回值将存储在缓存中的方法。 但是&#xff0c; Cacheable只是Spring的Guy为缓存而设计的一对注释​​中的一个&#xff0c;另一个是CacheEvict 。 像Cacheable一样&#xff0c; Cache…

centos 获取硬件序列号_如何在 Linux 上查找硬件规格

在 Linux 系统上有许多工具可用于查找硬件规格。-- Sk&#xff08;作者&#xff09;在 Linux 系统上有许多工具可用于查找硬件规格。在这里&#xff0c;我列出了四种最常用的工具&#xff0c;可以获取 Linux 系统的几乎所有硬件&#xff08;和软件&#xff09;细节。好在是这些…

位置服务器管理器,查看 DIMM 位置

键入&#xff1a;-> show /System/Memory/DIMMs -t locationTarget | Property | Value-----------------------------------------------------------------------/System/Memory/DIMMs/ | location | CMIOU0/CM/CMP/BOB00/CH0/DIMM (CPU MemoryDIMM_0 | | IO Unit 0 Memor…

Spring –持久层–编写实体并配置Hibernate

欢迎来到本教程的第二部分。 当您看到本文有多长时间时&#xff0c;请不要惊慌–我向您保证&#xff0c;这主要是简单的POJO和一些生成的代码。 在开始之前&#xff0c;我们需要更新我们的Maven依赖项&#xff0c;因为我们现在将使用Hibernate和Spring。 将以下依赖项添加到pom…

无线服务器主机名是,wifi默认服务器主机名

wifi默认服务器主机名 内容精选换一换以CentOS 7操作系统的弹性云服务器为例&#xff1a;登录Linux弹性云服务器&#xff0c;查看“cloud-init”的配置文件。检查“/etc/cloud/cloud.cfg”文件中“update_hostname”是否被注释或者删除。如果没有被注释或者删除&#xff0c;则需…

pygame里面物体闪烁运动_利用自闪烁发光二极管探究小车在倾斜轨道上的运动规律...

2020年11月23日&#xff0c;周一&#xff0c;24小时安全值班。利用当班中午的时间&#xff0c;微主在创客空间测试了自闪烁发光二极管在匀加速运动中的效果&#xff0c;结果还比较满意。将小车放置在倾斜的轨道上&#xff0c;将自闪烁发光二极管和纽扣电池构成频闪光源&#xf…

python网络爬虫与信息提取 学习笔记day3

Day3&#xff1a; 只需两行代码解析html或xml信息 具体代码实现:day3_1 注意BeautifulSoup的B和S需要大写&#xff0c;因为python大小写敏感 import requests r requests.get("http://python123.io/ws/demo.html") r.text demo r.text from bs4 import Beauti…

番石榴文件:Java文件管理

正如我在这里 &#xff0c; 这里 &#xff0c; 这里和这里所讨论的那样&#xff0c; Groovy和Java SE 7都为Java文件管理提供了改进。 但是&#xff0c;当特定的Java应用程序尚不能使用Java SE 7或Groovy进行文件管理时&#xff0c;仍然可以通过使用Guava的Files类获得改进的文…

顺序查找

顺序查找属于查找中较容易的一个方法&#xff0c;且对数据是否已经排序没有要求&#xff0c;是很常用的一个查找算法。 但缺点是必须一个一个数字进行比较查找&#xff0c;查找所需步骤可能较多。 顺序查找算法的思想是&#xff0c;将目标与待查找数据进行比较&#xff0c;若发…

王者荣耀微信哪个服务器人最少,王者荣耀:微信区王者人数锐减,大神们都去哪了?这些原因很真实...

原标题&#xff1a;王者荣耀&#xff1a;微信区王者人数锐减&#xff0c;大神们都去哪了&#xff1f;这些原因很真实王者荣耀&#xff1a;微信区王者人数锐减&#xff0c;大神们都去哪了&#xff1f;这些原因很真实大家好&#xff01;王者荣耀S16赛季已经开启一月之余&#xff…

一个div压在另一个div上面_【CSS小分享】用CSS画一个新拟态风格键盘

什么是新拟态新拟态的英文名称是“Neumorphism”&#xff0c;也有人称为“Soft UI”。简单讲&#xff0c;新拟态是一种图形样式&#xff0c;其原理是通过模拟真实物体来为界面的UI元素赋予真实感。新拟态风格起源于dribbble&#xff0c;后面陆续被收录在2020设计趋势预测里面&a…

JBoss BRMS与JasperReports进行报告

介绍 Jasperreports是一个免费的可下载库&#xff0c;可用于为Java EE应用程序生成丰富的报告。 本指南还提供了使用Jasper iReport设计器生成报告模板的步骤。 软件需求 JBoss BRMS 5.3&#xff08;从客户门户网站http://access.redhat.com &#xff09; JasperReports 4.6…

java字符串 删除指定字符的那些事

需求如下&#xff1a; 1.算出2周以前的时间&#xff0c;以正常日期格式返回 2.如果月份和日期前面有0需要去掉返回结果&#xff0c;比如&#xff1a;2017-08-15 就需要显示2017-8-15。 Calendar calendar Calendar.getInstance();calendar.add(Calendar.DATE, -14);Date date…

Hibernate中Hql查询

这篇随笔将会记录hql的常用的查询语句&#xff0c;为日后查看提供便利。 在这里通过定义了三个类&#xff0c;Special、Classroom、Student来做测试&#xff0c;Special与Classroom是一对多&#xff0c;Classroom与Student是一对多的关系&#xff0c;这里仅仅贴出这三个bean的属…

Java代码质量工具–概述

最近&#xff0c;我有机会在本地IT社区聚会上介绍了该主题。 这是基本演示&#xff1a; Java代码质量工具 以及更有意义的思维导图&#xff1a; 但是&#xff0c;我认为我需要更深入地探讨这一主题。 这篇博客文章应该像是在此方向上进行进一步调查的起点。 1. CodePro Anal…

利用yum升级Centos6的gcc版本,使其支持C++11

下面的可以在centos6下工作&#xff0c;centos7下有问题。可能是因为centos下的scl我是拷贝的文件&#xff0c;没有完全验证centos6下肯定没问题。 https://my.oschina.net/u/583362/blog/682123 和https://www.quyu.net/info/876.html 拷贝其关键内容就是&#xff1a; 1.使用 …

cuda版本查看_ubuntu安装CUDA

0 写在前面安装环境&#xff1a;ubuntu18.04以及GTX1050Ti笔记本为什么要安装CUDA&#xff1f; 参考百科&#xff0c;CUDA是英伟达推出的集成技术&#xff0c;通过该技术可利用GeForce 8 以后的GPU或者较新的Quadro GPU进行计算。例如典型的tensorflow-GPU和pyCUDA安装之前都要…

HTML 标签列表(功能排序) HTML 参考手册- (HTML5 标准)

HTML 标签列表&#xff08;功能排序&#xff09; HTML 参考手册- (HTML5 标准) 功能排序 New : HTML5 新标签 标签描述基础 <!DOCTYPE> 定义文档类型。<html>定义一个 HTML 文档<title>为文档定义一个标题<body>定义文档的主体<h1> to <h6>…

idea新建scala文件_IDEA maven项目中新建.scala文件

本文首发于我的博客[IDEA maven项目中新建.scala文件]分为三步第一步、IDEA中安装scala插件1、搜索安装File-Sittings-Plugins-搜索安装scala2、安装完成重启安装完成之后点击重启idea第二步、下载、安装、配置Scala1、下载安装Scala SDK本体搜索引擎搜索Scala SDK或者点我去Sc…

Linux中执行shell脚本的4种方法总结

文章来源&#xff1a;http://www.jb51.net/article/53924.htm 这篇文章主要介绍了Linux中执行shell脚本的4种方法总结,即在Linux中运行shell脚本的4种方法,需要的朋友可以参考下 bash shell 脚本的方法有多种&#xff0c;现在作个小结。假设我们编写好的shell脚本的文件名为hel…