📄 main.java
字号:
package zjkdata;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.sql.*;
import com.borland.jbcl.layout.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumnModel;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Main
extends JFrame {
UdpReceive udpreceive = new UdpReceive();
JPanel contentPane;
JMenuBar jMenuBarMain = new JMenuBar();
JLabel jLabel1 = new JLabel();
JToolBar jToolBar2 = new JToolBar();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
static JLabel SystemLable = new JLabel();
TitledBorder titledBorder1;
XYLayout xYLayout1 = new XYLayout();
JScrollPane jScrollPane1 = new JScrollPane();
final String[] columnNames = {
"等级", "告警时间", "接收到的UDP告警消息"};
Object[][] rowDate = new Object[3][3];
DefaultTableModel tableModel = new DefaultTableModel(rowDate, columnNames);
static JTable dataTable = new JTable();
TitledBorder titledBorder2;
JMenu jMenu1 = new JMenu();
JMenu jMenu2 = new JMenu();
JMenuItem jMenuItem1 = new JMenuItem();
JMenuItem jMenuItem2 = new JMenuItem();
JMenuItem jMenuItem3 = new JMenuItem();
JMenu jMenu3 = new JMenu();
JMenuItem jMenuItem4 = new JMenuItem();
//Construct the frame
public Main() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
this.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel)this.getContentPane();
titledBorder1 = new TitledBorder("");
titledBorder2 = new TitledBorder("");
contentPane.setLayout(xYLayout1);
this.setResizable(false);
this.setSize(new Dimension(800, 600));
this.setTitle("综合告警协议转换系统(harris)");
contentPane.setBackground(SystemColor.text);
contentPane.setMinimumSize(new Dimension(800, 600));
contentPane.setPreferredSize(new Dimension(800, 600));
jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
jLabel1.setIcon(new ImageIcon("image/harris.jpg"));
jLabel1.setText("");
jLabel1.setVerticalAlignment(SwingConstants.TOP);
jToolBar2.setBorder(BorderFactory.createEtchedBorder());
jToolBar2.setOpaque(true);
jButton1.setBorderPainted(true);
jButton1.setIcon(new ImageIcon("image/para.png"));
jButton1.setText("");
jButton1.addActionListener(new Main_jButton1_actionAdapter(this));
jButton2.setIcon(new ImageIcon("image/run.png"));
jButton2.setText("");
jButton2.addActionListener(new Main_jButton2_actionAdapter(this));
jButton3.setIcon(new ImageIcon("image/stop.png"));
jButton3.setText("");
jButton3.addActionListener(new Main_jButton3_actionAdapter(this));
jButton4.setIcon(new ImageIcon("image/help.png"));
jButton4.setText("");
jMenuBarMain.setToolTipText("");
SystemLable.setBackground(Color.white);
SystemLable.setFont(new java.awt.Font("DialogInput", 0, 12));
SystemLable.setForeground(Color.blue);
SystemLable.setAlignmentY( (float) 0.5);
SystemLable.setBorder(BorderFactory.createLineBorder(Color.black));
SystemLable.setDebugGraphicsOptions(0);
SystemLable.setMaximumSize(new Dimension(26, 31));
SystemLable.setOpaque(true);
SystemLable.setPreferredSize(new Dimension(26, 31));
SystemLable.setRequestFocusEnabled(true);
SystemLable.setToolTipText("");
SystemLable.setVerifyInputWhenFocusTarget(true);
SystemLable.setDisplayedMnemonic('0');
SystemLable.setHorizontalAlignment(SwingConstants.LEFT);
SystemLable.setHorizontalTextPosition(SwingConstants.RIGHT);
SystemLable.setIconTextGap(4);
SystemLable.setText(" ");
SystemLable.setVerticalAlignment(SwingConstants.CENTER);
SystemLable.setVerticalTextPosition(SwingConstants.CENTER);
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.
HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.
VERTICAL_SCROLLBAR_NEVER);
jScrollPane1.setFont(new java.awt.Font("Dialog", 0, 12));
jScrollPane1.setForeground(Color.black);
jScrollPane1.setAutoscrolls(false);
jScrollPane1.setBorder(BorderFactory.createEtchedBorder());
jScrollPane1.setOpaque(false);
dataTable.setFont(new java.awt.Font("Dialog", 0, 12));
dataTable.setEnabled(false);
dataTable.setAutoscrolls(false);
dataTable.setBorder(BorderFactory.createLineBorder(Color.black));
dataTable.setDebugGraphicsOptions(0);
dataTable.setOpaque(true);
dataTable.setRequestFocusEnabled(true);
dataTable.setToolTipText("");
dataTable.setVerifyInputWhenFocusTarget(true);
dataTable.setColumnSelectionAllowed(false);
dataTable.setRowMargin(1);
dataTable.setRowSelectionAllowed(true);
dataTable.setShowHorizontalLines(true);
dataTable.setShowVerticalLines(true);
this.setJMenuBar(jMenuBarMain);
jMenu1.setText("系统参数");
jMenu2.setText("数据采集");
jMenuItem1.setText("参数设置");
jMenuItem1.addActionListener(new Main_jMenuItem1_actionAdapter(this));
jMenuItem2.setText("采集启动");
jMenuItem2.addActionListener(new Main_jMenuItem2_actionAdapter(this));
jMenuItem3.setText("采集停止");
jMenuItem3.addActionListener(new Main_jMenuItem3_actionAdapter(this));
jMenu3.setText("系统帮助");
jMenuItem4.setText("关于");
jToolBar2.add(jButton1, null);
jToolBar2.add(jButton2, null);
jToolBar2.add(jButton3, null);
jToolBar2.add(jButton4, null);
contentPane.add(jScrollPane1, new XYConstraints(1, 435, 796, 83));
jScrollPane1.getViewport().add(dataTable, null);
contentPane.add(SystemLable, new XYConstraints(0, 516, 800, 0));
contentPane.add(jLabel1, new XYConstraints(261, 30, 538, 352));
contentPane.add(jToolBar2, new XYConstraints(0, 0, 800, 0));
jMenuBarMain.add(jMenu1);
jMenuBarMain.add(jMenu2);
jMenuBarMain.add(jMenu3);
jMenu1.add(jMenuItem1);
jMenu2.add(jMenuItem2);
jMenu2.add(jMenuItem3);
jMenu3.add(jMenuItem4);
dataTable.setModel(tableModel);
dataTable.getTableHeader().setFont(new Font("Dialog", 0, 12));
dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
dataTable.getColumnModel().getColumn(0).setPreferredWidth(40);
dataTable.getColumnModel().getColumn(1).setPreferredWidth(125);
dataTable.getColumnModel().getColumn(2).setPreferredWidth(625);
dataTable.getTableHeader().setReorderingAllowed(false);
dataTable.setRowHeight(18);
dataTable.getColumnModel().getColumn(0).setResizable(false);
dataTable.getColumnModel().getColumn(1).setResizable(false);
dataTable.getColumnModel().getColumn(2).setResizable(false);
}
//参数设置窗口打开事件响应
public void paraset() {
if (ValueAll.paraframeshow == false) {
ParaFrame paraframe = new ParaFrame();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = paraframe.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
paraframe.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
paraframe.show();
ValueAll.paraframeshow = true;
}
}
//采集启动事件响应
public void run() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String DBUrl = "jdbc:odbc:datalink";
Connection Conn = DriverManager.getConnection(DBUrl);
Statement Stmt = Conn.createStatement();
ResultSet rsSQLSelect = Stmt.executeQuery("Select * from parameter");
if (rsSQLSelect.next()) {
if (ValueAll.serverrun == false) {
Thread udprevThread = new Thread(udpreceive);
udprevThread.setName("Thead-UdpReceive");
udprevThread.start();
ValueAll.serverrun = true;
SystemLable.setIcon(new ImageIcon("image/statusrun.png"));
SystemLable.setText("系统运行状态:数据采集程序已经运行,准备接收数据!");
SystemLable.setForeground(Color.blue);
}
else {
Toolkit.getDefaultToolkit().beep();
SystemLable.setIcon(new ImageIcon("image/statuserr.png"));
SystemLable.setText("系统运行状态:采集数据程序正在运行,不能再次启动!");
SystemLable.setForeground(Color.red);
JOptionPane.showMessageDialog(null, "数据采集程序正在运行,不能再次启动!");
}
}
else {
Toolkit.getDefaultToolkit().beep();
SystemLable.setIcon(new ImageIcon("image/statuserr.png"));
SystemLable.setText("系统运行状态:系统数据采集参数未设置,请设置后再启动!");
SystemLable.setForeground(Color.red);
JOptionPane.showMessageDialog(null, "系统数据采集参数未设置,请设置后再启动!");
}
Conn.close();
Stmt.close();
}
catch (Exception eee) {
////////////////////////////////////////////////////////
//System.out.println(eee);
}
}
//采集停止事件响应
public void stop() {
try {
udpreceive.stopReceive();
Toolkit.getDefaultToolkit().beep();
SystemLable.setIcon(new ImageIcon("image/statusalm.png"));
SystemLable.setText("系统运行状态:数据采集停止!");
SystemLable.setForeground(Color.red);
ValueAll.serverrun = false;
}
catch (Exception ex) {
}
}
//菜单及工具栏按钮事件动作
void jButton1_actionPerformed(ActionEvent e) {
paraset();
}
void jButton2_actionPerformed(ActionEvent e) {
run();
}
void jButton3_actionPerformed(ActionEvent e) {
if (JOptionPane.showConfirmDialog(null, "该操作将停止数据采集!是否继续执行停止操作?", "提示",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE) ==
JOptionPane.OK_OPTION) {
stop();
}
}
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
if (JOptionPane.showConfirmDialog(null, "该操作将退出数据采集系统!是否继续执行退出操作?", "提示",
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE) ==
JOptionPane.OK_OPTION) {
System.exit(0);
}
return;
}
}
void jMenuItem1_actionPerformed(ActionEvent e) {
paraset();
}
void jMenuItem2_actionPerformed(ActionEvent e) {
run();
}
void jMenuItem3_actionPerformed(ActionEvent e) {
if (JOptionPane.showConfirmDialog(null, "该操作将停止数据采集!是否继续执行停止操作?", "提示",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE) ==
JOptionPane.OK_OPTION) {
stop();
}
}
}
class Main_jButton2_actionAdapter
implements java.awt.event.ActionListener {
Main adaptee;
Main_jButton2_actionAdapter(Main adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class Main_jButton1_actionAdapter
implements java.awt.event.ActionListener {
Main adaptee;
Main_jButton1_actionAdapter(Main adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class Main_jButton3_actionAdapter
implements java.awt.event.ActionListener {
Main adaptee;
Main_jButton3_actionAdapter(Main adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class Main_jMenuItem1_actionAdapter
implements java.awt.event.ActionListener {
Main adaptee;
Main_jMenuItem1_actionAdapter(Main adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem1_actionPerformed(e);
}
}
class Main_jMenuItem2_actionAdapter
implements java.awt.event.ActionListener {
Main adaptee;
Main_jMenuItem2_actionAdapter(Main adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem2_actionPerformed(e);
}
}
class Main_jMenuItem3_actionAdapter
implements java.awt.event.ActionListener {
Main adaptee;
Main_jMenuItem3_actionAdapter(Main adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem3_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -