Browse Source

javaswing系统工具样式

master
lixl1 3 years ago
parent
commit
1a5c9ab71d
  1. 547
      src/main/java/com/insigma/ui/SwingFrame.java

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

@ -1,6 +1,7 @@
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.border.EmptyBorder; import javax.swing.border.EmptyBorder;
@ -66,41 +67,49 @@ public class SwingFrame extends JFrame implements ActionListener {
* Launch the application. * Launch the application.
*/ */
public static void run() { public static void run() {
// try { try {
// for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
// if ("Nimbus".equals(info.getName())) { if ("Nimbus".equals(info.getName())) {
// javax.swing.UIManager.setLookAndFeel(info.getClassName()); javax.swing.UIManager.setLookAndFeel(info.getClassName());
// break; break;
// } }
// } }
// }catch(Exception e) { }catch(Exception e) {
// System.out.println(e); System.out.println(e);
// }
try {//设置界面样式 Look And Feel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
} }
EventQueue.invokeLater(() -> { // try {//设置界面样式 Look And Feel
try { // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingFrame frame = new SwingFrame(); // } catch (Exception e) {
frame.setTitle("系统工具"); //设置显示窗口标题 // e.printStackTrace();
// }
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SwingFrame frame = new SwingFrame();
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() { public SwingFrame() throws IOException {
contentPane = new JPanel(); contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
@ -114,19 +123,22 @@ public class SwingFrame extends JFrame implements ActionListener {
contentPane.add(tabbedPane); contentPane.add(tabbedPane);
repairPanel = new JPanel();//系统优化面板 repairPanel = new JPanel();//系统优化面板
repairPanel.setForeground(Color.GRAY); repairPanel.setForeground(Color.WHITE);
repairPanel.setBackground(new Color(220, 220, 220)); repairPanel.setBackground(Color.WHITE);
tabbedPane.addTab("系统优化", null, repairPanel, null); tabbedPane.addTab("系统优化", null, repairPanel, null);
repairPanel.setLayout(null); repairPanel.setLayout(null);
JLabel label_5 = new JLabel("系统优化"); JLabel label_5 = new JLabel("系统优化");
label_5.setBounds(42, 35, 120, 40); label_5.setBounds(42, 35, 120, 40);
label_5.setForeground(Color.RED); label_5.setForeground(new Color(0, 0, 0));
label_5.setFont(new Font("微软雅黑", Font.PLAIN, 30)); label_5.setFont(new Font("微软雅黑", Font.PLAIN, 30));
repairPanel.add(label_5); repairPanel.add(label_5);
JButton btnNewButton = new JButton("开始优化"); JButton btnNewButton = new JButton("开始优化");
btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 15)); btnNewButton.setForeground(Color.WHITE);
btnNewButton.setBackground(new Color(55, 205, 255));
btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 20));
btnNewButton.setBorderPainted(false);//去掉按钮的边框的设置
btnNewButton.setBounds(617, 63, 113, 40); btnNewButton.setBounds(617, 63, 113, 40);
btnNewButton.addActionListener(this); btnNewButton.addActionListener(this);
repairPanel.add(btnNewButton); repairPanel.add(btnNewButton);
@ -137,12 +149,12 @@ public class SwingFrame extends JFrame implements ActionListener {
repairPanel.add(label_6); repairPanel.add(label_6);
JSeparator separator_1 = new JSeparator(); JSeparator separator_1 = new JSeparator();
separator_1.setBackground(Color.LIGHT_GRAY); separator_1.setBackground(Color.WHITE);
separator_1.setBounds(27, 116, 715, 5); separator_1.setBounds(27, 116, 715, 5);
repairPanel.add(separator_1); repairPanel.add(separator_1);
JCheckBox chckbxNewCheckBox = new JCheckBox("重启服务",true); JCheckBox chckbxNewCheckBox = new JCheckBox("重启服务",true);
chckbxNewCheckBox.setBackground(new Color(220, 220, 220)); chckbxNewCheckBox.setBackground(Color.WHITE);
chckbxNewCheckBox.setBounds(53, 130, 162, 27); chckbxNewCheckBox.setBounds(53, 130, 162, 27);
chckbxNewCheckBox.setFont(new Font("微软雅黑", Font.PLAIN, 18)); chckbxNewCheckBox.setFont(new Font("微软雅黑", Font.PLAIN, 18));
repairPanel.add(chckbxNewCheckBox); repairPanel.add(chckbxNewCheckBox);
@ -168,23 +180,33 @@ public class SwingFrame extends JFrame implements ActionListener {
lblNewLabel_2.setBounds(34, 309, 240, 185); lblNewLabel_2.setBounds(34, 309, 240, 185);
repairPanel.add(lblNewLabel_2); repairPanel.add(lblNewLabel_2);
JButton btnNewButton_8 = new JButton("打开服务管理器"); JLabel lblNewLabel_3 = new JLabel("<html><u>打开服务管理器</u><html>");
btnNewButton_8.setFont(new Font("微软雅黑", Font.PLAIN, 15)); lblNewLabel_3.setForeground(new Color(30, 144, 255));
btnNewButton_8.setBounds(582, 132, 148, 40); lblNewLabel_3.setFont(new Font("微软雅黑", Font.PLAIN, 20));
btnNewButton_8.addActionListener(this); lblNewLabel_3.addMouseListener(new MouseAdapter() {
repairPanel.add(btnNewButton_8); @Override
public void mouseClicked(MouseEvent e) {
try{
new WindowsTomcatMysql().openServer();
}catch (Exception ex){
ex.printStackTrace();
}
}
});
lblNewLabel_3.setBounds(164, 127, 140, 31);
repairPanel.add(lblNewLabel_3);
JPanel memoryPanel = new JPanel();//调整内存面板 JPanel memoryPanel = new JPanel();//调整内存面板
memoryPanel.setBorder(UIManager.getBorder("Button.border")); memoryPanel.setBorder(UIManager.getBorder("Button.border"));
memoryPanel.setAlignmentX(Component.LEFT_ALIGNMENT); memoryPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
memoryPanel.setForeground(Color.GRAY); memoryPanel.setForeground(Color.WHITE);
memoryPanel.setBackground(new Color(220, 220, 220)); memoryPanel.setBackground(Color.WHITE);
tabbedPane.addTab("调整内存", null, memoryPanel, null); tabbedPane.addTab("调整内存", null, memoryPanel, null);
memoryPanel.setLayout(null); memoryPanel.setLayout(null);
JLabel lblNewLabel = new JLabel("调整内存"); JLabel lblNewLabel = new JLabel("调整内存");
lblNewLabel.setBounds(60, 31, 125, 34); lblNewLabel.setBounds(60, 31, 125, 34);
lblNewLabel.setForeground(Color.RED); lblNewLabel.setForeground(Color.BLACK);
lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 30)); lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 30));
memoryPanel.add(lblNewLabel); memoryPanel.add(lblNewLabel);
@ -204,16 +226,17 @@ 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(e -> { btnNewButton_7.addActionListener(new ActionListener() {
try { @SneakyThrows
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);
@ -224,16 +247,17 @@ 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(e -> { button_1.addActionListener(new ActionListener() {
try { @SneakyThrows
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);
@ -244,16 +268,17 @@ 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(e -> { button_2.addActionListener(new ActionListener() {
try { @SneakyThrows
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);
@ -264,37 +289,44 @@ 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(e -> { button_3.addActionListener(new ActionListener() {
try { @SneakyThrows
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.setForeground(Color.WHITE);
btnNewButton_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
btnNewButton_1.setBackground(new Color(55, 205, 255));
btnNewButton_1.setBorderPainted(false);//去掉按钮的边框的设置
btnNewButton_1.setBounds(566, 472, 113, 40); btnNewButton_1.setBounds(566, 472, 113, 40);
btnNewButton_1.addActionListener(e -> { btnNewButton_1.addActionListener(new ActionListener() {
//暂定保存内容 public void actionPerformed(ActionEvent e) {
//暂定保存内容
}
}); });
// btnNewButton_1.setContentAreaFilled(false);//按钮设置为透明
// btnNewButton_1.setBorder(BorderFactory.createRaisedBevelBorder());//设置凸起来的按钮
// btnNewButton_1.setBorder(BorderFactory.createLoweredBevelBorder()); //设置凹起来的按钮
// btnNewButton_1.setBorderPainted(false);//去掉按钮的边框的设置
// String path = "C:\\Users\\86177\\Desktop\\www.png";
// File file = new File(path);
// Image image = ImageIO.read(file);
// btnNewButton_1.setIcon(new ImageIcon(image.getScaledInstance(50, 50, image.SCALE_DEFAULT)));
btnNewButton_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
memoryPanel.add(btnNewButton_1); memoryPanel.add(btnNewButton_1);
backupsPanel = new JPanel();//数据库备份、还原面板 backupsPanel = new JPanel();//数据库备份、还原面板
backupsPanel.setBackground(new Color(220, 220, 220)); backupsPanel.setBackground(Color.WHITE);
tabbedPane.addTab("数据库备份", null, backupsPanel, null); tabbedPane.addTab("数据库备份", null, backupsPanel, null);
backupsPanel.setLayout(null); backupsPanel.setLayout(null);
@ -330,10 +362,10 @@ public class SwingFrame extends JFrame implements ActionListener {
lblNewLabel_15.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_15.setFont(new Font("微软雅黑", Font.PLAIN, 16));
backupsPanel.add(lblNewLabel_15); backupsPanel.add(lblNewLabel_15);
JButton btnNewButton_3 = new JButton("数据库备份"); // JButton btnNewButton_3 = new JButton("数据库备份");
btnNewButton_3.setBounds(32, 351, 113, 27); // btnNewButton_3.setBounds(32, 351, 113, 27);
btnNewButton_3.addActionListener(this); // btnNewButton_3.addActionListener(this);
backupsPanel.add(btnNewButton_3); // backupsPanel.add(btnNewButton_3);
JLabel label_11 = new JLabel("<html><body>数据库还原将覆盖当前系统中所有人为产生的数据,不可恢复,需谨慎操作。<br><body></html>"); JLabel label_11 = new JLabel("<html><body>数据库还原将覆盖当前系统中所有人为产生的数据,不可恢复,需谨慎操作。<br><body></html>");
label_11.setBounds(382, 55, 238, 74); label_11.setBounds(382, 55, 238, 74);
@ -345,22 +377,57 @@ public class SwingFrame extends JFrame implements ActionListener {
label_12.setFont(new Font("微软雅黑", Font.PLAIN, 16)); label_12.setFont(new Font("微软雅黑", Font.PLAIN, 16));
backupsPanel.add(label_12); backupsPanel.add(label_12);
JButton button = new JButton("数据库还原"); // JButton button = new JButton("数据库还原");
button.setBounds(451, 351, 113, 27); // button.setBounds(451, 351, 113, 27);
button.addActionListener(this); // button.addActionListener(this);
backupsPanel.add(button); // backupsPanel.add(button);
JLabel lblNewLabel_16 = new JLabel("注:当系统遇到极端情况导致无法登陆时,系统卸载可进行数据库备份,重装或升级之后进行数据库还原。"); JLabel lblNewLabel_16 = new JLabel("<html><b>注:当系统遇到极端情况导致无法登陆时,系统卸载可进行数据库备份,重装或升级之后进行数据库还原。</b><html>");
lblNewLabel_16.setForeground(Color.GREEN);
lblNewLabel_16.setFont(new Font("微软雅黑", Font.PLAIN, 15)); lblNewLabel_16.setFont(new Font("微软雅黑", Font.PLAIN, 15));
lblNewLabel_16.setBounds(14, 494, 710, 18); lblNewLabel_16.setBounds(14, 494, 710, 18);
backupsPanel.add(lblNewLabel_16); backupsPanel.add(lblNewLabel_16);
JLabel label_1 = new JLabel("<html><u>数据库备份</u><html>");
label_1.setForeground(new Color(30, 144, 255));
label_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
label_1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try{
tabbedPane.addTab("数据库备份", null, startBackupPanel, null);
tabbedPane.setSelectedComponent(startBackupPanel);
}catch (Exception ex){
ex.printStackTrace();
}
}
});
label_1.setBounds(32, 377, 105, 31);
backupsPanel.add(label_1);
JLabel label_3 = new JLabel("<html><u>数据库还原</u><html>");
label_3.setForeground(new Color(30, 144, 255));
label_3.setFont(new Font("微软雅黑", Font.PLAIN, 20));
label_3.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try{
tabbedPane.addTab("数据库还原", null, startRestorePanel, null);
tabbedPane.setSelectedComponent(startRestorePanel);
}catch (Exception ex){
ex.printStackTrace();
}
}
});
label_3.setBounds(451, 377, 105, 31);
backupsPanel.add(label_3);
Panel upgradePanel = new Panel();//系统升级面板 Panel upgradePanel = new Panel();//系统升级面板
upgradePanel.setBackground(new Color(220, 220, 220)); upgradePanel.setBackground(Color.WHITE);
tabbedPane.addTab("系统升级", null, upgradePanel, null); tabbedPane.addTab("系统升级", null, upgradePanel, null);
upgradePanel.setLayout(null); upgradePanel.setLayout(null);
JLabel lblNewLabel_8 = new JLabel("安装包/升级包下载"); JLabel lblNewLabel_8 = new JLabel("<html><b>安装包/升级包下载</b><html>");
lblNewLabel_8.setFont(new Font("微软雅黑", Font.PLAIN, 20)); lblNewLabel_8.setFont(new Font("微软雅黑", Font.PLAIN, 20));
lblNewLabel_8.setBounds(47, 47, 181, 28); lblNewLabel_8.setBounds(47, 47, 181, 28);
upgradePanel.add(lblNewLabel_8); upgradePanel.add(lblNewLabel_8);
@ -370,7 +437,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;
@ -393,19 +460,19 @@ 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(new Color(30, 144, 255));
} }
}); });
upgradePanel.add(lblNewLabel_9); upgradePanel.add(lblNewLabel_9);
JLabel lblNewLabel_10 = new JLabel("客服电话:400-8600-797-1、400-9608-590-5。"); JLabel lblNewLabel_10 = new JLabel("<html><b>客服电话:400-8600-797-1、400-9608-590-5。</b><html>");
lblNewLabel_10.setFont(new Font("微软雅黑", Font.PLAIN, 20)); lblNewLabel_10.setFont(new Font("微软雅黑", Font.PLAIN, 20));
lblNewLabel_10.setBounds(47, 161, 462, 28); lblNewLabel_10.setBounds(47, 161, 462, 28);
upgradePanel.add(lblNewLabel_10); upgradePanel.add(lblNewLabel_10);
@ -416,21 +483,23 @@ public class SwingFrame extends JFrame implements ActionListener {
upgradePanel.add(lblNewLabel_11); upgradePanel.add(lblNewLabel_11);
startRepairPanel = new JPanel(); startRepairPanel = new JPanel();
startRepairPanel.setBackground(new Color(220, 220, 220)); startRepairPanel.setBackground(Color.WHITE);
startRepairPanel.setLayout(null); startRepairPanel.setLayout(null);
lblNewLabel_6 = new JLabel("系统正在加速优化中,建议不要随意随意操作停止!"); lblNewLabel_6 = new JLabel("系统正在加速优化中,建议不要随意随意操作关闭!");
lblNewLabel_6.setBounds(57, 34, 378, 18); lblNewLabel_6.setBounds(57, 34, 446, 18);
lblNewLabel_6.setForeground(new Color(255, 0, 0)); lblNewLabel_6.setForeground(new Color(255, 0, 0));
lblNewLabel_6.setFont(new Font("微软雅黑", Font.PLAIN, 18)); lblNewLabel_6.setFont(new Font("微软雅黑", Font.PLAIN, 18));
startRepairPanel.add(lblNewLabel_6); startRepairPanel.add(lblNewLabel_6);
JButton btnNewButton_2 = new JButton("停止优化");
btnNewButton_2.setBounds(495, 65, 113, 27);
startRepairPanel.add(btnNewButton_2);
JProgressBar progressBar = new JProgressBar(); JProgressBar progressBar = new JProgressBar();
progressBar.setBackground(Color.WHITE);
progressBar.setFont(new Font("微软雅黑", Font.PLAIN, 15));
// MyJProgressBar progressBar = new MyJProgressBar(); // MyJProgressBar progressBar = new MyJProgressBar();
progressBar.setBounds(57, 65, 412, 27); progressBar.setBounds(57, 65, 555, 27);
// 设置进度的 最小值 和 最大值 // 设置进度的 最小值 和 最大值
progressBar.setMinimum(MIN_PROGRESS); progressBar.setMinimum(MIN_PROGRESS);
progressBar.setMaximum(MAX_PROGRESS); progressBar.setMaximum(MAX_PROGRESS);
@ -439,10 +508,13 @@ public class SwingFrame extends JFrame implements ActionListener {
// 绘制百分比文本(进度条中间显示的百分数) // 绘制百分比文本(进度条中间显示的百分数)
progressBar.setStringPainted(true); progressBar.setStringPainted(true);
// 添加进度改变通知 // 添加进度改变通知
progressBar.addChangeListener(e -> { // progressBar.addChangeListener(new ChangeListener() {
// System.out.println("当前进度值: " + progressBar.getValue() + "; " + // @Override
// "进度百分比: " + progressBar.getPercentComplete()); // public void stateChanged(ChangeEvent e) {
}); // // System.out.println("当前进度值: " + progressBar.getValue() + "; " +
// // "进度百分比: " + progressBar.getPercentComplete());
// }
// });
// 添加到内容面板 // 添加到内容面板
startRepairPanel.add(progressBar); startRepairPanel.add(progressBar);
@ -463,122 +535,186 @@ public class SwingFrame extends JFrame implements ActionListener {
scrollPane.setViewportView(textPane); scrollPane.setViewportView(textPane);
startBackupPanel = new JPanel();//执行数据库备份面板 startBackupPanel = new JPanel();//执行数据库备份面板
startBackupPanel.setBackground(new Color(220, 220, 220)); startBackupPanel.setBackground(Color.WHITE);
JButton btnNewButton_4 = new JButton("返回");
btnNewButton_4.setFont(new Font("微软雅黑", Font.PLAIN, 15));
btnNewButton_4.setBounds(14, 13, 113, 35);
btnNewButton_4.addActionListener(this);
startBackupPanel.setLayout(null); startBackupPanel.setLayout(null);
startBackupPanel.add(btnNewButton_4);
JLabel lblNewLabel_17 = new JLabel("数据库备份"); JLabel lblNewLabel_17 = new JLabel("数据库备份");
lblNewLabel_17.setBounds(94, 60, 100, 27); lblNewLabel_17.setBounds(27, 62, 100, 27);
lblNewLabel_17.setFont(new Font("微软雅黑", Font.PLAIN, 20)); lblNewLabel_17.setFont(new Font("微软雅黑", Font.PLAIN, 20));
startBackupPanel.add(lblNewLabel_17); startBackupPanel.add(lblNewLabel_17);
JLabel lblNewLabel_18 = new JLabel("存储目录:"); JLabel lblNewLabel_18 = new JLabel("存储目录:");
lblNewLabel_18.setBounds(71, 90, 85, 27); lblNewLabel_18.setBounds(27, 102, 85, 27);
lblNewLabel_18.setFont(new Font("微软雅黑", Font.PLAIN, 15)); lblNewLabel_18.setFont(new Font("微软雅黑", Font.PLAIN, 15));
startBackupPanel.add(lblNewLabel_18); startBackupPanel.add(lblNewLabel_18);
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(356, 103, 73, 24);
btnNewButton_5.addActionListener(e -> { btnNewButton_5.addActionListener(new ActionListener() {
JFileChooser jfC = new JFileChooser(); @Override
// jfC.setMultiSelectionEnabled(true);//文件是否多选!参数为true或false public void actionPerformed(ActionEvent e) {
jfC.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//设置文件的打开模式(只能选文件夹) JFileChooser jfC = new JFileChooser();
jfC.setDialogTitle("请选择要上传的文件夹"); // jfC.setMultiSelectionEnabled(true);//文件是否多选!参数为true或false
int value = jfC.showOpenDialog(SwingFrame.this); jfC.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//设置文件的打开模式(只能选文件夹)
if(value == JFileChooser.APPROVE_OPTION) { jfC.setDialogTitle("请选择要上传的文件夹");
File dirFile = jfC.getSelectedFile();//返回选中的文件 int value = jfC.showOpenDialog(SwingFrame.this);
textField_5.setText(dirFile.getAbsolutePath()); if(value == JFileChooser.APPROVE_OPTION) {
File dirFile = jfC.getSelectedFile();//返回选中的文件
textField_5.setText(dirFile.getAbsolutePath());
}
} }
}); });
startBackupPanel.add(btnNewButton_5); startBackupPanel.add(btnNewButton_5);
JLabel lblNewLabel_19 = new JLabel("数据库备份的格式为“zip”"); JLabel lblNewLabel_19 = new JLabel("数据库备份的格式为“zip”");
lblNewLabel_19.setBounds(170, 120, 186, 18); lblNewLabel_19.setBounds(114, 136, 186, 18);
lblNewLabel_19.setFont(new Font("微软雅黑", Font.PLAIN, 15)); lblNewLabel_19.setFont(new Font("微软雅黑", Font.PLAIN, 15));
startBackupPanel.add(lblNewLabel_19); startBackupPanel.add(lblNewLabel_19);
JButton btnNewButton_6 = new JButton("开始备份"); JButton btnNewButton_6 = new JButton("开始备份");
btnNewButton_6.setFont(new Font("微软雅黑", Font.PLAIN, 15)); btnNewButton_6.setForeground(Color.WHITE);
btnNewButton_6.setBounds(206, 186, 113, 35); btnNewButton_6.setFont(new Font("微软雅黑", Font.PLAIN, 20));
btnNewButton_6.addActionListener(e -> { btnNewButton_6.setBackground(new Color(55, 205, 255));
btnNewButton_6.setBounds(606, 98, 113, 35);
btnNewButton_6.setBorderPainted(false);//去掉按钮的边框的设置
btnNewButton_6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
}); });
startBackupPanel.add(btnNewButton_6); startBackupPanel.add(btnNewButton_6);
textField_5 = new JTextField(); textField_5 = new JTextField();
textField_5.setBounds(170, 92, 319, 24); textField_5.setBounds(114, 103, 245, 24);
textField_5.setFont(new Font("微软雅黑", Font.PLAIN, 15)); textField_5.setFont(new Font("微软雅黑", Font.PLAIN, 15));
startBackupPanel.add(textField_5); startBackupPanel.add(textField_5);
textField_5.setColumns(10); textField_5.setColumns(10);
JLabel label_7 = new JLabel("<html><u>返回</u><html>");
label_7.setForeground(new Color(30, 144, 255));
label_7.setFont(new Font("微软雅黑", Font.PLAIN, 20));
label_7.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try{
tabbedPane.setSelectedComponent(backupsPanel);
}catch (Exception ex){
ex.printStackTrace();
}
}
});
label_7.setBounds(27, 13, 53, 31);
startBackupPanel.add(label_7);
startRestorePanel = new JPanel(); startRestorePanel = new JPanel();
startRestorePanel.setLayout(null); startRestorePanel.setLayout(null);
startRestorePanel.setBackground(new Color(220, 220, 220)); startRestorePanel.setBackground(Color.WHITE);
JButton button_4 = new JButton("返回"); // JButton button_4 = new JButton("返回");
button_4.setFont(new Font("微软雅黑", Font.PLAIN, 15)); // button_4.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_4.setBounds(14, 13, 113, 35); // button_4.setBounds(14, 13, 113, 35);
button_4.addActionListener(this); // button_4.addActionListener(this);
startRestorePanel.add(button_4); // startRestorePanel.add(button_4);
JLabel label = new JLabel("数据库还原"); JLabel label = new JLabel("数据库还原");
label.setFont(new Font("微软雅黑", Font.PLAIN, 20)); label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
label.setBounds(94, 60, 100, 27); label.setBounds(14, 57, 100, 27);
startRestorePanel.add(label); startRestorePanel.add(label);
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(14, 97, 120, 24);
button_5.addActionListener(e -> { button_5.addActionListener(new ActionListener() {
JFileChooser jfC = new JFileChooser(); @Override
jfC.setFileFilter(new FileFilter() { public void actionPerformed(ActionEvent e) {
@Override JFileChooser jfC = new JFileChooser();
public String getDescription() { jfC.setFileFilter(new FileFilter() {
return "ZIP压缩文件(*.zip)"; @Override
} public String getDescription() {
@Override return "ZIP压缩文件(*.zip)";
public boolean accept(File f) { }
return f.getName().toLowerCase().endsWith(".zip"); @Override
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);
JLabel label_2 = new JLabel("数据库备份的格式为“zip”"); JLabel label_2 = new JLabel("数据库备份的格式为“zip”");
label_2.setFont(new Font("微软雅黑", Font.PLAIN, 15)); label_2.setFont(new Font("微软雅黑", Font.PLAIN, 15));
label_2.setBounds(170, 120, 186, 18); label_2.setBounds(131, 126, 186, 18);
startRestorePanel.add(label_2); startRestorePanel.add(label_2);
JButton button_6 = new JButton("开始还原"); JButton button_6 = new JButton("开始还原");
button_6.setFont(new Font("微软雅黑", Font.PLAIN, 15)); button_6.setForeground(Color.WHITE);
button_6.setBounds(206, 186, 113, 35); button_6.setFont(new Font("微软雅黑", Font.PLAIN, 20));
button_6.setBackground(new Color(55, 205, 255));
button_6.setBounds(594, 90, 113, 35);
button_6.setBorderPainted(false);//去掉按钮的边框的设置
button_6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
startRestorePanel.add(button_6); startRestorePanel.add(button_6);
textField = new JTextField(""); textField = new JTextField();
textField.setFont(new Font("微软雅黑", Font.PLAIN, 15)); textField.setFont(new Font("微软雅黑", Font.PLAIN, 15));
textField.setColumns(10); textField.setColumns(10);
textField.setBounds(207, 91, 330, 24); textField.setBounds(128, 97, 310, 24);
startRestorePanel.add(textField); startRestorePanel.add(textField);
JLabel label_4 = new JLabel("<html><u>返回</u><html>");
label_4.setForeground(new Color(30, 144, 255));
label_4.setFont(new Font("微软雅黑", Font.PLAIN, 20));
label_4.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try{
tabbedPane.setSelectedComponent(backupsPanel);
}catch (Exception ex){
ex.printStackTrace();
}
}
});
label_4.setBounds(14, 13, 53, 31);
startRestorePanel.add(label_4);
JPanel textPanel = new JPanel(); JPanel textPanel = new JPanel();
textPanel.setLayout(null); textPanel.setLayout(null);
textPanel.setBackground(new Color(220, 220, 220)); textPanel.setBackground(Color.WHITE);
tabbedPane.addTab("测试", null, textPanel, null); tabbedPane.addTab("测试", null, textPanel, null);
JButton button_7 = new JButton("开始数据库服务"); JButton button_7 = new JButton("开始数据库服务");
button_7.setFont(new Font("微软雅黑", Font.PLAIN, 15)); button_7.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_7.setBounds(14, 13, 170, 35); button_7.setBounds(14, 13, 170, 35);
@ -588,11 +724,13 @@ 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(e -> { button_8.addActionListener(new ActionListener() {
try { public void actionPerformed(ActionEvent e) {
new WindowsTomcatMysql().stopDbService(); try {
} catch (Exception exception) { new WindowsTomcatMysql().stopDbService();
exception.printStackTrace(); } catch (Exception exception) {
exception.printStackTrace();
}
} }
}); });
textPanel.add(button_8); textPanel.add(button_8);
@ -600,11 +738,13 @@ 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(e -> { button_9.addActionListener(new ActionListener() {
try { public void actionPerformed(ActionEvent e) {
new WindowsTomcatMysql().startMwService(); try {
} catch (Exception exception) { new WindowsTomcatMysql().startMwService();
exception.printStackTrace(); } catch (Exception exception) {
exception.printStackTrace();
}
} }
}); });
textPanel.add(button_9); textPanel.add(button_9);
@ -612,11 +752,13 @@ 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(e -> { button_10.addActionListener(new ActionListener() {
try { public void actionPerformed(ActionEvent e) {
new WindowsTomcatMysql().stopMwService(); try {
} catch (Exception exception) { new WindowsTomcatMysql().stopMwService();
exception.printStackTrace(); } catch (Exception exception) {
exception.printStackTrace();
}
} }
}); });
textPanel.add(button_10); textPanel.add(button_10);
@ -658,34 +800,27 @@ public class SwingFrame extends JFrame implements ActionListener {
// }).start(); // }).start();
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String buttonCommand = e.getActionCommand(); String buttonCommand = e.getActionCommand();
if("打开服务管理器".equals(buttonCommand)) { // if(buttonCommand.equals("打开服务管理器")) {
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");
new WindowsTomcatMysql().openServer(); // new WindowsTomcatMysql().openServer();
}catch (Exception ex){ // }catch (Exception ex){
ex.printStackTrace(); // ex.printStackTrace();
} // }
}else if("开始优化".equals(buttonCommand)) { // }
try{ if(buttonCommand.equals("开始优化")) {
tabbedPane.addTab("开始优化界面", null, startRepairPanel, null); try{
tabbedPane.setSelectedComponent(startRepairPanel); tabbedPane.addTab("开始优化界面", null, startRepairPanel, null);
new WindowsTomcatMysql().startDbService(); tabbedPane.setSelectedComponent(startRepairPanel);
new WindowsTomcatMysql().startDbService(); // new WindowsTomcatMysql().startDbService();
}catch (Exception ex){ // new WindowsTomcatMysql().startDbService();
ex.printStackTrace(); }catch (Exception ex){
} ex.printStackTrace();
}else if("数据库备份".equals(buttonCommand)) {
tabbedPane.addTab("数据库备份", null, startBackupPanel, null);
tabbedPane.setSelectedComponent(startBackupPanel);
}else if("数据库还原".equals(buttonCommand)) {
tabbedPane.addTab("数据库还原", null, startRestorePanel, null);
tabbedPane.setSelectedComponent(startRestorePanel);
}else if("返回".equals(buttonCommand)) {
tabbedPane.setSelectedComponent(backupsPanel);
} }
} }
}
} }
Loading…
Cancel
Save