Browse Source

增加测试代码事件

master
VIVIMAN 3 years ago
parent
commit
a95b82fc7b
  1. 264
      src/main/java/com/insigma/ui/SwingFrame.java

264
src/main/java/com/insigma/ui/SwingFrame.java

@ -1,13 +1,9 @@
package com.insigma.ui; package com.insigma.ui;
import com.insigma.service.impl.WindowsTomcatMysql; import com.insigma.service.impl.WindowsTomcatMysql;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import javax.swing.*;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File; import java.io.File;
@ -17,43 +13,36 @@ import java.net.URISyntaxException;
import java.awt.EventQueue; import java.awt.EventQueue;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.border.EmptyBorder; import javax.swing.JButton;
import javax.swing.event.ChangeEvent; import java.awt.Panel;
import javax.swing.event.ChangeListener; import java.awt.Toolkit;
import javax.swing.JButton;
import java.awt.Panel; import javax.swing.JTabbedPane;
import java.awt.Toolkit; import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JTabbedPane; import java.awt.Color;
import java.awt.Font; import java.awt.Desktop;
import javax.swing.JTextField; import javax.swing.JLabel;
import java.awt.Color; import javax.swing.JScrollPane;
import java.awt.Desktop; import javax.swing.JSeparator;
import javax.swing.JLabel; import javax.swing.UIManager;
import javax.swing.JScrollPane; import javax.swing.ImageIcon;
import javax.swing.JSeparator; import java.awt.event.MouseAdapter;
import javax.swing.UIManager; import java.awt.event.MouseEvent;
import javax.swing.ImageIcon; import java.net.URI;
import java.awt.event.ActionListener; import javax.swing.JCheckBox;
import java.awt.event.MouseAdapter; import javax.swing.JFileChooser;
import java.awt.event.MouseEvent; import javax.swing.JProgressBar;
import java.io.IOException; import javax.swing.JTextPane;
import java.net.URI;
import java.net.URISyntaxException;
import java.awt.event.ActionEvent;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JProgressBar;
import javax.swing.Timer;
import javax.swing.JTextPane;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
import java.awt.Component; import java.awt.Component;
/**
* @author BeiJing-GWY /**
*/ * @author BeiJing-GWY
@Slf4j */
@Slf4j
public class SwingFrame extends JFrame implements ActionListener { public class SwingFrame extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private JPanel contentPane; private JPanel contentPane;
@ -69,10 +58,10 @@ public class SwingFrame extends JFrame implements ActionListener {
private JPanel startBackupPanel; private JPanel startBackupPanel;
private JPanel startRestorePanel; private JPanel startRestorePanel;
private JTabbedPane tabbedPane; private JTabbedPane tabbedPane;
private JTextField textField_1; private JTextField textField_1;
private JTextField textField_2; private JTextField textField_2;
private JTextField textField_3; private JTextField textField_3;
private JTextField textField_4; private JTextField textField_4;
/** /**
* Launch the application. * Launch the application.
*/ */
@ -92,29 +81,26 @@ public class SwingFrame extends JFrame implements ActionListener {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
EventQueue.invokeLater(new Runnable() { EventQueue.invokeLater(() -> {
public void run() { try {
try { SwingFrame frame = new SwingFrame();
SwingFrame frame = new SwingFrame(); frame.setTitle("系统工具"); //设置显示窗口标题
frame.setTitle("系统工具"); //设置显示窗口标题
// frame.setSize(1600,400);//设置显示窗口大小 // frame.setSize(1600,400);//设置显示窗口大小
// frame.getContentPane().setBackground(Color.blue);//设置显示窗体颜色 // frame.getContentPane().setBackground(Color.blue);//设置显示窗体颜色
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置窗口是否可以关闭 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置窗口是否可以关闭
frame.setBounds(100, 100, 910, 580); frame.setBounds(100, 100, 910, 580);
frame.setVisible(true); frame.setVisible(true);
frame.setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JavaSwing\\src\\main\\java\\com\\insigma\\ui\\favicon.jpg")); frame.setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JavaSwing\\src\\main\\java\\com\\insigma\\ui\\favicon.jpg"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}
} }
}); });
} }
/** /**
* Create the frame. * Create the frame.
* @throws IOException
*/ */
public SwingFrame() throws IOException { public SwingFrame() {
contentPane = new JPanel(); contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
@ -218,11 +204,16 @@ public class SwingFrame extends JFrame implements ActionListener {
JButton btnNewButton_7 = new JButton(msgBtn); JButton btnNewButton_7 = new JButton(msgBtn);
btnNewButton_7.setBounds(72, 138, 329, 59); btnNewButton_7.setBounds(72, 138, 329, 59);
btnNewButton_7.setFont(new Font("微软雅黑", Font.PLAIN, 15)); btnNewButton_7.setFont(new Font("微软雅黑", Font.PLAIN, 15));
btnNewButton_7.addActionListener(new ActionListener() { btnNewButton_7.addActionListener(e -> {
@SneakyThrows try {
public void actionPerformed(ActionEvent e) {
new WindowsTomcatMysql().setDbSize(200000); new WindowsTomcatMysql().setDbSize(200000);
} catch (Exception exception) {
exception.printStackTrace();
}
try {
new WindowsTomcatMysql().setMwSize(200000); new WindowsTomcatMysql().setMwSize(200000);
} catch (Exception exception) {
exception.printStackTrace();
} }
}); });
memoryPanel.add(btnNewButton_7); memoryPanel.add(btnNewButton_7);
@ -233,11 +224,16 @@ public class SwingFrame extends JFrame implements ActionListener {
JButton button_1 = new JButton(msgBtn16G); JButton button_1 = new JButton(msgBtn16G);
button_1.setBounds(72, 227, 329, 59); button_1.setBounds(72, 227, 329, 59);
button_1.setFont(new Font("微软雅黑", Font.PLAIN, 15)); button_1.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_1.addActionListener(new ActionListener() { button_1.addActionListener(e -> {
@SneakyThrows try {
public void actionPerformed(ActionEvent e) {
new WindowsTomcatMysql().setDbSize(160000); new WindowsTomcatMysql().setDbSize(160000);
} catch (Exception exception) {
exception.printStackTrace();
}
try {
new WindowsTomcatMysql().setMwSize(160000); new WindowsTomcatMysql().setMwSize(160000);
} catch (Exception exception) {
exception.printStackTrace();
} }
}); });
memoryPanel.add(button_1); memoryPanel.add(button_1);
@ -248,11 +244,16 @@ public class SwingFrame extends JFrame implements ActionListener {
JButton button_2 = new JButton(msgBtn8G); JButton button_2 = new JButton(msgBtn8G);
button_2.setBounds(72, 314, 329, 59); button_2.setBounds(72, 314, 329, 59);
button_2.setFont(new Font("微软雅黑", Font.PLAIN, 15)); button_2.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_2.addActionListener(new ActionListener() { button_2.addActionListener(e -> {
@SneakyThrows try {
public void actionPerformed(ActionEvent e) {
new WindowsTomcatMysql().setDbSize(80000); new WindowsTomcatMysql().setDbSize(80000);
} catch (Exception exception) {
exception.printStackTrace();
}
try {
new WindowsTomcatMysql().setMwSize(80000); new WindowsTomcatMysql().setMwSize(80000);
} catch (Exception exception) {
exception.printStackTrace();
} }
}); });
memoryPanel.add(button_2); memoryPanel.add(button_2);
@ -263,20 +264,23 @@ public class SwingFrame extends JFrame implements ActionListener {
JButton button_3 = new JButton(msgBtn4G); JButton button_3 = new JButton(msgBtn4G);
button_3.setBounds(72, 399, 329, 59); button_3.setBounds(72, 399, 329, 59);
button_3.setFont(new Font("微软雅黑", Font.PLAIN, 15)); button_3.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_3.addActionListener(new ActionListener() { button_3.addActionListener(e -> {
@SneakyThrows try {
public void actionPerformed(ActionEvent e) {
new WindowsTomcatMysql().setDbSize(40000); new WindowsTomcatMysql().setDbSize(40000);
} catch (Exception exception) {
exception.printStackTrace();
}
try {
new WindowsTomcatMysql().setMwSize(40000); new WindowsTomcatMysql().setMwSize(40000);
} catch (Exception exception) {
exception.printStackTrace();
} }
}); });
memoryPanel.add(button_3); memoryPanel.add(button_3);
JButton btnNewButton_1 = new JButton("保存"); JButton btnNewButton_1 = new JButton("保存");
btnNewButton_1.setBounds(566, 472, 113, 40); btnNewButton_1.setBounds(566, 472, 113, 40);
btnNewButton_1.addActionListener(new ActionListener() { btnNewButton_1.addActionListener(e -> {
public void actionPerformed(ActionEvent e) { //暂定保存内容
//暂定保存内容
}
}); });
// btnNewButton_1.setContentAreaFilled(false);//按钮设置为透明 // btnNewButton_1.setContentAreaFilled(false);//按钮设置为透明
// btnNewButton_1.setBorder(BorderFactory.createRaisedBevelBorder());//设置凸起来的按钮 // btnNewButton_1.setBorder(BorderFactory.createRaisedBevelBorder());//设置凸起来的按钮
@ -366,6 +370,7 @@ public class SwingFrame extends JFrame implements ActionListener {
lblNewLabel_9.setBounds(57, 88, 420, 18); lblNewLabel_9.setBounds(57, 88, 420, 18);
upgradePanel.addMouseListener(new MouseAdapter() { upgradePanel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e){ //鼠标点击事件 public void mouseClicked(MouseEvent e){ //鼠标点击事件
@SuppressWarnings("unused") @SuppressWarnings("unused")
URI uri = null; URI uri = null;
@ -388,9 +393,11 @@ public class SwingFrame extends JFrame implements ActionListener {
} }
} }
@Override
public void mouseEntered(MouseEvent e) { //鼠标移入事件 public void mouseEntered(MouseEvent e) { //鼠标移入事件
lblNewLabel_9.setForeground(Color.red); lblNewLabel_9.setForeground(Color.red);
} }
@Override
public void mouseExited(MouseEvent e) { //鼠标移出事件 public void mouseExited(MouseEvent e) { //鼠标移出事件
lblNewLabel_9.setForeground(Color.blue); lblNewLabel_9.setForeground(Color.blue);
} }
@ -432,12 +439,9 @@ public class SwingFrame extends JFrame implements ActionListener {
// 绘制百分比文本(进度条中间显示的百分数) // 绘制百分比文本(进度条中间显示的百分数)
progressBar.setStringPainted(true); progressBar.setStringPainted(true);
// 添加进度改变通知 // 添加进度改变通知
progressBar.addChangeListener(new ChangeListener() { progressBar.addChangeListener(e -> {
@Override // System.out.println("当前进度值: " + progressBar.getValue() + "; " +
public void stateChanged(ChangeEvent e) { // "进度百分比: " + progressBar.getPercentComplete());
// System.out.println("当前进度值: " + progressBar.getValue() + "; " +
// "进度百分比: " + progressBar.getPercentComplete());
}
}); });
// 添加到内容面板 // 添加到内容面板
startRepairPanel.add(progressBar); startRepairPanel.add(progressBar);
@ -482,18 +486,15 @@ public class SwingFrame extends JFrame implements ActionListener {
JButton btnNewButton_5 = new JButton("更改"); JButton btnNewButton_5 = new JButton("更改");
btnNewButton_5.setFont(new Font("微软雅黑", Font.PLAIN, 15)); btnNewButton_5.setFont(new Font("微软雅黑", Font.PLAIN, 15));
btnNewButton_5.setBounds(486, 91, 100, 24); btnNewButton_5.setBounds(486, 91, 100, 24);
btnNewButton_5.addActionListener(new ActionListener() { btnNewButton_5.addActionListener(e -> {
@Override JFileChooser jfC = new JFileChooser();
public void actionPerformed(ActionEvent e) { // jfC.setMultiSelectionEnabled(true);//文件是否多选!参数为true或false
JFileChooser jfC = new JFileChooser(); jfC.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//设置文件的打开模式(只能选文件夹)
// jfC.setMultiSelectionEnabled(true);//文件是否多选!参数为true或false jfC.setDialogTitle("请选择要上传的文件夹");
jfC.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//设置文件的打开模式(只能选文件夹) int value = jfC.showOpenDialog(SwingFrame.this);
jfC.setDialogTitle("请选择要上传的文件夹"); if(value == JFileChooser.APPROVE_OPTION) {
int value = jfC.showOpenDialog(SwingFrame.this); File dirFile = jfC.getSelectedFile();//返回选中的文件
if(value == JFileChooser.APPROVE_OPTION) { textField_5.setText(dirFile.getAbsolutePath());
File dirFile = jfC.getSelectedFile();//返回选中的文件
textField_5.setText(dirFile.getAbsolutePath());
}
} }
}); });
startBackupPanel.add(btnNewButton_5); startBackupPanel.add(btnNewButton_5);
@ -506,11 +507,8 @@ public class SwingFrame extends JFrame implements ActionListener {
JButton btnNewButton_6 = new JButton("开始备份"); JButton btnNewButton_6 = new JButton("开始备份");
btnNewButton_6.setFont(new Font("微软雅黑", Font.PLAIN, 15)); btnNewButton_6.setFont(new Font("微软雅黑", Font.PLAIN, 15));
btnNewButton_6.setBounds(206, 186, 113, 35); btnNewButton_6.setBounds(206, 186, 113, 35);
btnNewButton_6.addActionListener(new ActionListener() { btnNewButton_6.addActionListener(e -> {
@Override
public void actionPerformed(ActionEvent e) {
}
}); });
startBackupPanel.add(btnNewButton_6); startBackupPanel.add(btnNewButton_6);
@ -538,31 +536,25 @@ public class SwingFrame extends JFrame implements ActionListener {
JButton button_5 = new JButton("上传文件:"); JButton button_5 = new JButton("上传文件:");
button_5.setFont(new Font("微软雅黑", Font.PLAIN, 15)); button_5.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_5.setBounds(94, 91, 116, 24); button_5.setBounds(94, 91, 116, 24);
button_5.addActionListener(new ActionListener() { button_5.addActionListener(e -> {
@Override JFileChooser jfC = new JFileChooser();
public void actionPerformed(ActionEvent e) { jfC.setFileFilter(new FileFilter() {
JFileChooser jfC = new JFileChooser(); @Override
jfC.setFileFilter(new FileFilter() { public String getDescription() {
@Override return "ZIP压缩文件(*.zip)";
public String getDescription() { }
return "ZIP压缩文件(*.zip)"; @Override
} public boolean accept(File f) {
@Override return f.getName().toLowerCase().endsWith(".zip");
public boolean accept(File f) {
if(f.getName().toLowerCase().endsWith(".zip")) {
return true;
}
return false;
}
});
// jfC.setMultiSelectionEnabled(true);//文件是否多选!参数为true或false
jfC.setFileSelectionMode(JFileChooser.FILES_ONLY);//设置文件的打开模式(只能选文件夹)
jfC.setDialogTitle("请选择要上传的文件夹");
int value = jfC.showOpenDialog(SwingFrame.this);
if(value == JFileChooser.APPROVE_OPTION) {
File dirFile = jfC.getSelectedFile();//返回选中的文件
textField.setText(dirFile.getAbsolutePath());
} }
});
// jfC.setMultiSelectionEnabled(true);//文件是否多选!参数为true或false
jfC.setFileSelectionMode(JFileChooser.FILES_ONLY);//设置文件的打开模式(只能选文件夹)
jfC.setDialogTitle("请选择要上传的文件夹");
int value = jfC.showOpenDialog(SwingFrame.this);
if(value == JFileChooser.APPROVE_OPTION) {
File dirFile = jfC.getSelectedFile();//返回选中的文件
textField.setText(dirFile.getAbsolutePath());
} }
}); });
startRestorePanel.add(button_5); startRestorePanel.add(button_5);
@ -596,9 +588,11 @@ public class SwingFrame extends JFrame implements ActionListener {
JButton button_8 = new JButton("停止数据库服务"); JButton button_8 = new JButton("停止数据库服务");
button_8.setFont(new Font("微软雅黑", Font.PLAIN, 15)); button_8.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_8.setBounds(14, 61, 170, 24); button_8.setBounds(14, 61, 170, 24);
button_8.addActionListener(new ActionListener() { button_8.addActionListener(e -> {
public void actionPerformed(ActionEvent e) { try {
new WindowsTomcatMysql().stopDbService();
} catch (Exception exception) {
exception.printStackTrace();
} }
}); });
textPanel.add(button_8); textPanel.add(button_8);
@ -606,9 +600,11 @@ public class SwingFrame extends JFrame implements ActionListener {
JButton button_9 = new JButton("开始中间件"); JButton button_9 = new JButton("开始中间件");
button_9.setFont(new Font("微软雅黑", Font.PLAIN, 15)); button_9.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_9.setBounds(14, 98, 170, 35); button_9.setBounds(14, 98, 170, 35);
button_9.addActionListener(new ActionListener() { button_9.addActionListener(e -> {
public void actionPerformed(ActionEvent e) { try {
new WindowsTomcatMysql().startMwService();
} catch (Exception exception) {
exception.printStackTrace();
} }
}); });
textPanel.add(button_9); textPanel.add(button_9);
@ -616,9 +612,11 @@ public class SwingFrame extends JFrame implements ActionListener {
JButton button_10 = new JButton("停止中间件"); JButton button_10 = new JButton("停止中间件");
button_10.setFont(new Font("微软雅黑", Font.PLAIN, 15)); button_10.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_10.setBounds(14, 153, 170, 35); button_10.setBounds(14, 153, 170, 35);
button_10.addActionListener(new ActionListener() { button_10.addActionListener(e -> {
public void actionPerformed(ActionEvent e) { try {
new WindowsTomcatMysql().stopMwService();
} catch (Exception exception) {
exception.printStackTrace();
} }
}); });
textPanel.add(button_10); textPanel.add(button_10);
@ -663,7 +661,7 @@ public class SwingFrame extends JFrame implements ActionListener {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String buttonCommand = e.getActionCommand(); String buttonCommand = e.getActionCommand();
if(buttonCommand.equals("打开服务管理器")) { if("打开服务管理器".equals(buttonCommand)) {
try{ try{
// Runtime rt = Runtime.getRuntime();runBak // Runtime rt = Runtime.getRuntime();runBak
// Process p = rt.exec("cmd.exe /c compmgmt.msc"); // Process p = rt.exec("cmd.exe /c compmgmt.msc");
@ -671,7 +669,7 @@ public class SwingFrame extends JFrame implements ActionListener {
}catch (Exception ex){ }catch (Exception ex){
ex.printStackTrace(); ex.printStackTrace();
} }
}else if(buttonCommand.equals("开始优化")) { }else if("开始优化".equals(buttonCommand)) {
try{ try{
tabbedPane.addTab("开始优化界面", null, startRepairPanel, null); tabbedPane.addTab("开始优化界面", null, startRepairPanel, null);
tabbedPane.setSelectedComponent(startRepairPanel); tabbedPane.setSelectedComponent(startRepairPanel);
@ -680,13 +678,13 @@ public class SwingFrame extends JFrame implements ActionListener {
}catch (Exception ex){ }catch (Exception ex){
ex.printStackTrace(); ex.printStackTrace();
} }
}else if(buttonCommand.equals("数据库备份")) { }else if("数据库备份".equals(buttonCommand)) {
tabbedPane.addTab("数据库备份", null, startBackupPanel, null); tabbedPane.addTab("数据库备份", null, startBackupPanel, null);
tabbedPane.setSelectedComponent(startBackupPanel); tabbedPane.setSelectedComponent(startBackupPanel);
}else if(buttonCommand.equals("数据库还原")) { }else if("数据库还原".equals(buttonCommand)) {
tabbedPane.addTab("数据库还原", null, startRestorePanel, null); tabbedPane.addTab("数据库还原", null, startRestorePanel, null);
tabbedPane.setSelectedComponent(startRestorePanel); tabbedPane.setSelectedComponent(startRestorePanel);
}else if(buttonCommand.equals("返回")) { }else if("返回".equals(buttonCommand)) {
tabbedPane.setSelectedComponent(backupsPanel); tabbedPane.setSelectedComponent(backupsPanel);
} }
} }

Loading…
Cancel
Save