⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frame1.java~105~

📁 会议名片管理程序 3/9条形码生成
💻 JAVA~105~
📖 第 1 页 / 共 5 页
字号:
package cardmanager;import java.sql.*;import java.awt.*;import java.awt.event.*;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import javax.swing.*;import javax.swing.border.*;import javax.swing.ListSelectionModel;import javax.swing.event.ListSelectionListener;import javax.swing.event.ListSelectionEvent;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.SwingUtilities;import javax.swing.table.AbstractTableModel;import javax.swing.table.DefaultTableModel;import javax.swing.filechooser.*;import java.util.*;import java.io.*;import javax.comm.*;import cardmanager.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class Frame1 extends JFrame implements Runnable,SerialPortEventListener{  //默认全局变量  public  String meetingName="会议名称";               //默认会议名称  public  String defaultSN = "3102104000001";          //默认条形码编号  public static String pswdDefault = "";               //默认主界面之密码  public static String pswdDefaultAd ="";              //默认高级功能选项之密码  public String bookedSN;                              // 已进入会场SN  private JPanel contentPane;  private JMenuBar jMenuBarInit     = new JMenuBar();   //菜单条  Code39  code39Bar = new Code39();                     //条形码控件(继承自JLabel)  private JMenu jMenuSystem         = new JMenu();      //系统设置菜单  private JMenuItem jMenuPswdSet    = new JMenuItem();  //密码设置菜单项  private JMenuItem jMenuPswdGet    = new JMenuItem();  //权限密码菜单项  private JMenuItem jMenuNameSet    = new JMenuItem();  //设定会议名称菜单项  private JMenuItem jMenuPrint      = new JMenuItem();  //打印名片菜单项  private JMenuItem jMenuSystemExit = new JMenuItem();  //退出系统菜单项  private JMenu  jMenuAdvanced          = new  JMenu();    //高级功能菜单  private JMenu  jMenuPswdControl       = new JMenu();     //密码控制菜单  private JMenuItem jMenuPswdSetAd      = new JMenuItem(); //密码设置菜单项--用于控制查看到访记录  private JMenuItem jMenuPswdGetAd      = new JMenuItem(); //取回高级功能权限密码  private JMenuItem jMenuArrivalView    = new JMenuItem(); //查看到访记录菜单项  private JMenu jMenuFunction        = new  JMenu();     //功能菜单  private JMenuItem  newItem         = new  JMenuItem(); //添加记录菜单项  private JMenuItem  resetItem       = new  JMenuItem(); //复位菜单项--用于请空各个文本域  private JMenuItem  updateItem      = new  JMenuItem(); //更新纪录菜单项  private JMenuItem  deleteItem      = new  JMenuItem(); //删除记录菜单项  private JMenuItem  bySNItem        = new  JMenuItem(); //浏览全部记录之菜单项  private JMenuItem  byDistrictItem  = new  JMenuItem(); //按地区浏览之菜单项  private JMenuItem  bySortItem      = new  JMenuItem(); //按行业浏览之菜单项-----已废弃  private JMenuItem  countItem       = new  JMenuItem(); //查看登记记录总数  private JMenuItem  bySeveralItem   = new  JMenuItem(); //按照几个或一个条件查询记录  private JMenu jMenuHelp           = new JMenu();       //帮助菜单  private JMenuItem jMenuUseHelp    = new JMenuItem();   //已废弃  private JMenuItem jMenuAbout      = new JMenuItem();   //About......//About......  private JToolBar jToolBar         = new JToolBar();    //定义工具栏  private JButton jButton1          = new JButton();     //添加纪录  private JButton jButton2          = new JButton();     //删除记录  private JButton jButton3          = new JButton();     //更新纪录  private JButton jButton4          = new JButton();     //浏览所有记录----bySNItem  private JButton jButton7          = new JButton();     //打印名片  private JButton jButton8          = new JButton();     //使用帮助  private JButton jButton9          = new JButton();     //查找--一个或多个条件----bySevaralItem  private JButton jButton10         = new JButton();     //复位--resetItem  private ImageIcon image1;                              //添加纪录图标  private ImageIcon image2;                              //删除纪录图标  private ImageIcon image3;                              //更新纪录图标  private ImageIcon image4;                              //浏览所有记录纪录图标  private ImageIcon image7;                              //打印名片图标  private ImageIcon image8;                              //使用帮助图标  private ImageIcon image9;                              //按条件查找记录图标  private ImageIcon image10;                             //会标  private ImageIcon imageIconMeeting;//  private String[] conditions = { "与      ",//                                   "或      " };//  private JComboBox jComboBox1 = new JComboBox(conditions);  //PanelLeft主界面的列表  public DefaultTableModel model;                         //列表模型  public JTable tableLeft;                                //列表  public String[] InitString = new String[1000];  public String[] columnNames = {"列表"};  public Object[][] addObject= new Object[1000][1];  public String SN;  //其他信息,放在paneRight的北部  //以下是放于paneRight的一系列标签  private JLabel nameLabel        = new JLabel();          //姓名  private JLabel companyLabel     = new JLabel();          //单位  private JLabel positionLabel    = new JLabel();          //职位  private JLabel officephoneLabel = new JLabel();          //办公室电话  private JLabel emailLabel       = new JLabel();          //电子邮件  private JLabel mobileLabel      = new JLabel();          //手机  private JLabel webpageLabel     = new JLabel();          //网址  private JLabel faxLabel         = new JLabel();          //传真  private JLabel callLabel        = new JLabel();          //寻呼机  private JLabel departLabel      = new JLabel();          //部门  private JLabel postcodeLabel    = new JLabel();          //邮政编码  private JLabel addressLabel     = new JLabel();          //通信地址  private JLabel numberLabel      = new JLabel();          //编号  private JLabel sortLabel        = new JLabel();          //分类  //以下是放于paneRight的一系列文本域  private JTextField nameField         = new JTextField(23);//姓名  private JTextField companyField      = new JTextField(52);//单位  private JTextField positionField     = new JTextField(23);//职位  private JTextField officephoneField  = new JTextField(23);//办公室电话  private JTextField emailField        = new JTextField(23);//电子邮件  private JTextField mobileField       = new JTextField(23);//手机  private JTextField webaddressField   = new JTextField(23);//网址  private JTextField faxField          = new JTextField(23);//传真  private JTextField callField         = new JTextField(23);//寻呼机  private JTextField departField       = new JTextField(23);//部门  private JTextField postcodeField     = new JTextField(23);//邮政编码  private JTextArea addressArea        = new JTextArea(2,52);//通信地址  private JTextField numberField        = new JTextField(23);//编号  private String[] sort = {"IT行业",                           "市场营销" ,                           "其他"                            //分类                          };  private JComboBox jComboBoxSort = new JComboBox(sort);  private Container c = getContentPane();		      //当前容器  public JPanel paneLeft               = new JPanel();        //frame的左边区域  public JPanel paneRight              = new JPanel();        //frame的右边区域  public JPanel otherInfoPanel         = new JPanel();        //信息面板,用于放置标签和文本域  public JPanel cardCanvasPanel        = new JPanel();        //卡片面画布板,用于显示打印预览的名片  public JPanel cardPanel              = new JPanel();        //预览的名片  private JLabel statusBar             = new JLabel();  private BorderLayout borderLayout1   = new BorderLayout();  GridBagLayout gridbag                = new GridBagLayout();  GridBagConstraints gbc               = new GridBagConstraints();//列表标签,置于paneLeft/*  private JList list = new JList();                           //列表 ,置于paneLeft  private DefaultListModel listModel = new DefaultListModel();;  private Border border1;  private TitledBorder titledBorder1;  private TitledBorder titledBorder2;  private TitledBorder titledBorder3;*/  private BorderLayout borderLayout2 = new BorderLayout();  private JPanel panelTop  = new JPanel();  private JPanel panelBottom  = new JPanel();  private JPanel panelWest  = new JPanel();  private JPanel panelEast  = new JPanel();  GridBagLayout gridbag1 = new GridBagLayout();  GridBagConstraints gbc1 = new GridBagConstraints();  // 数据库变量  public static String url;				// 数据库URL  public static Connection connect;		        // 连接变量  public static Statement statement;			// 连接状态  public static ResultSet resultSet;                    // 查询数据库返回对象  // 扫描部分使用变量  static CommPortIdentifier portId;	// 端口信息变量  static Enumeration portList;		// 存放端口名称的列表  InputStream inputStream;		// 输入流  SerialPort serialPort;		// 串口变量  Thread readThread;			// 串口通讯线程  private int flag=1;			// 设置接收串口数据标志  private String st="",st1="";		// 设置存放串口数据字符串  private JPanel jPanelSouth = new JPanel(); //用于放置条形码  private JPanel jPanelNorth = new JPanel(); //用于放置会标及会议名称  private JPanel jPanelCenter = new JPanel();//用于放置姓名职位单位  private BorderLayout borderLayout3 = new BorderLayout();  private GridLayout gridLayout1     = new GridLayout();  private JLabel jLabelName          = new JLabel();  //姓名  private JLabel jLabelCompany1      = new JLabel(); //具体单位  private JLabel jLabelCompany       = new JLabel(); //单位  private JLabel jLabelPosition1     = new JLabel(); //具体职位  private JLabel jLabelPosition      = new JLabel(); //职位  private JLabel jLabelName1         = new JLabel();//具体姓名  private JLabel jLabelNameMeeting   = new JLabel();//会议名称  private JLabel jLabelIcon          = new JLabel();//会标  private GridBagLayout gridBagLayout1 = new GridBagLayout();  private BorderLayout borderLayout4 = new BorderLayout();  //Construct the frame  public Frame1() {    c.setLayout(new BorderLayout());            //设置frame为BorderLayout布局方式    paneLeft.setLayout(new BorderLayout());     //设置左边面板为BorderLyaout布局方式    paneRight.setLayout(new BorderLayout());    //设置右边面板为BorderLayout布局方式    otherInfoPanel.setLayout(gridbag);          //设置信息面板为GridBagLayout布局方式    cardCanvasPanel.setLayout(new BorderLayout());    cardPanel.setLayout(gridbag1);    enableEvents(AWTEvent.WINDOW_EVENT_MASK);    //初始化布局(菜单,工具栏等等其他信息)    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }    // 连接数据库    try {      Class.forName("com.mysql.jdbc.Driver").newInstance();	                // 注册驱动器      connect=DriverManager.getConnection      ("jdbc:mysql:/localhost/mydb?useUnicode=true&characterEncoding=gb2312");	// 设置数据库url    }    // 处理异常    catch ( ClassNotFoundException cnfex )    {      cnfex.printStackTrace();    }    catch ( SQLException sqlex )    {      sqlex.printStackTrace();    }    catch ( Exception ex )    {      ex.printStackTrace();    }    // 准备打开串口    portList = CommPortIdentifier.getPortIdentifiers();    while (portList.hasMoreElements())    {      portId = (CommPortIdentifier) portList.nextElement();      if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) // 判断是否串口      {        if (portId.getName().equals("COM1"))  //判断是否第一个RS232串口        {          try          {            serialPort = (SerialPort) portId.open("SimpleReadApp", 2000); // 打开串口          }          catch (PortInUseException e) {}          try          {            inputStream = serialPort.getInputStream(); //取得串口数据流          } catch (IOException e) {}          try          {            serialPort.addEventListener(this);// 添加监听器          }          catch (TooManyListenersException e) {}          serialPort.notifyOnDataAvailable(true); //设置Notify函数          // 设置串口通信默认参数          try          {            serialPort.setSerialPortParams(9600,            SerialPort.DATABITS_8,            SerialPort.STOPBITS_1,            SerialPort.PARITY_NONE);          }          catch (UnsupportedCommOperationException e) {}           //新建一个通讯用线程          readThread = new Thread(this);          readThread.start();        }      }    }  }  //Component initialization  private void jbInit() throws Exception  {    image1 = new ImageIcon(cardmanager.Frame1.class.getResource("new.gif"));    image2 = new ImageIcon(cardmanager.Frame1.class.getResource("delete1.gif"));    image3 = new ImageIcon(cardmanager.Frame1.class.getResource("update.gif"));    image4 = new ImageIcon(cardmanager.Frame1.class.getResource("view.gif"));    image7 = new ImageIcon(cardmanager.Frame1.class.getResource("printer.gif"));    image8 = new ImageIcon(cardmanager.Frame1.class.getResource("help.gif"));    image9 = new ImageIcon(cardmanager.Frame1.class.getResource("search.gif"));    image10= new ImageIcon(cardmanager.Frame1.class.getResource("reset.gif"));    imageIconMeeting= new ImageIcon(cardmanager.Frame1.class.getResource("sjtulogo1.gif"));    contentPane = (JPanel) this.getContentPane();/*    border1 = new MatteBorder(null);    titledBorder1 = new TitledBorder("");    titledBorder2 = new TitledBorder("");    titledBorder3 = new TitledBorder("");*/    contentPane.setLayout(borderLayout1);    this.getContentPane().setBackground(Color.gray);    this.setSize(new Dimension(788, 462));    this.setTitle         ("会议名片管理系统");    statusBar.setBackground(SystemColor.window);    statusBar.setText      (" ");    //设置菜单名称    jMenuSystem.setBackground(new Color(200, 250, 250));    jMenuSystem.setFont(new java.awt.Font("Dialog", 0, 14));    jMenuSystem.setText    ("系统设置(S)");    jMenuPswdSet.setText   ("密码设置");    jMenuPswdSet.addActionListener(new ActionListener()  {      public void actionPerformed(ActionEvent e) {        jMenuPswdSet_actionPerformed(e);      }    });    jMenuPswdGet.setText   ("权限密码");    jMenuPswdGet.addActionListener(new ActionListener()  {      public void actionPerformed(ActionEvent e) {        jMenuPswdGet_actionPerformed(e);      }    });    jMenuNameSet.setText   ("会议名称设置");    jMenuNameSet.addActionListener(new ActionListener()  {      public void actionPerformed(ActionEvent e) {        jMenuNameSet_actionPerformed(e);      }    });    jMenuPrint.setText     ("打印名片");    jMenuPrint.addActionListener(new ActionListener()  {      public void actionPerformed(ActionEvent e) {        jMenuPrint_actionPerformed(e);      }    });    jMenuSystemExit.setText("退出");    jMenuSystemExit.addActionListener(new ActionListener()  {      public void actionPerformed(ActionEvent e) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -