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

📄 jctx.java

📁 图书馆管理程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.sql.*;
//主函数、主要类
public class JCTX{

public static void main(String []args)
{
new Frm_Main();
}
}

//实现类
class Frm_Main implements ActionListener //throws IOException
{
	int bz;
    JFrame frame;
    Container c;
    JMenuBar menuBar;
    JMenu mainMenu1;
    JMenu mainMenu2;
    JMenu mainMenu3;
    JMenuItem subMenu1[] = new JMenuItem[5];
    JMenuItem subMenu2[] = new JMenuItem[7];
    JMenuItem subMenu3[] = new JMenuItem[2];
    JButton toolBarButton[] = new JButton[8];
    JToolBar toolBar;
//////////////////////////////////////////////
    String strTip[] = {"查询您要找的学生记录...","添加学生记录...","删除已有的学生记录","修改学生记录...","保存你的操作结果","向下逐个浏览记录","退出本系统..."};
//////////////////////////////////////////////
    String id = new String();
    String name = new String();
    String xb = new String();
    String dw = new String();
    String dh1 = new String();
    String dh2 = new String();
    String zw = new String();
    String email = new String();
    String dz = new String();
    String yb = new String();
//////////////////////////////////////////////

///////////////////////////////////////////////
    public JLabel idL = new JLabel("编号:");
    public JLabel nameL = new JLabel("姓名:");
    public JLabel xbL = new JLabel("性别:");
    public JLabel dwL = new JLabel("单位:");
    public JLabel zwL = new JLabel("职务:");
    public JLabel dh1L = new JLabel("电话一:");
    public JLabel dh2L = new JLabel("电话二:");
    public JLabel emailL = new JLabel("电子信箱:");
    public JLabel dzL = new JLabel("地址:");
    public JLabel ybL = new JLabel("邮编:");
    public JTextField idT = new JTextField();
    public JTextField nameT = new JTextField();
    public JTextField xbT = new JTextField();
    public JTextField dwT = new JTextField();
    public JTextField zwT = new JTextField();
    public JTextField dh1T = new JTextField();
    public JTextField dh2T = new JTextField();
    public JTextField emailT = new JTextField();
    public JTextField dzT = new JTextField();
    public JTextField ybT = new JTextField();
    public JButton next=new JButton("下一个");
//////////////////////////////////////////////
	public Connection con;
	public ResultSet rs;
	public Statement st;
//////////////////////////////////////////////
    public Frm_Main()
    {
/////////////////////////////////////////////////
        frame = new JFrame("简易名片信息管理子系统");
        c = frame.getContentPane();
        c.setLayout(null);
        menuBar = new JMenuBar();
        toolBar = new JToolBar();
        toolBar.setFloatable(false);
        frame.setJMenuBar(menuBar);
        frame.setResizable(false);
////////////////////////////////////////////////
        mainMenu1 = new JMenu("管理");
        String str1[] = {"添加用户","删除用户","查询用户"," ","退出"};
          for(int i=0;i<5;i++)
           {
                if(i==3)
                   mainMenu1.addSeparator();
                else
                   {
                    subMenu1[i] = new JMenuItem(str1[i]);
                    subMenu1[i].addActionListener(this);
                    mainMenu1.add(subMenu1[i]);
                     }
            }
         menuBar.add(mainMenu1);
/////////////////////////////////////////////////
         mainMenu2 = new JMenu("维护名片信息");
         String str2[] = {"查询记录","添加记录","删除记录","修改记录","保存结果"};
         for(int i=0;i<5;i++)
         {
             subMenu2[i] = new JMenuItem(str2[i]);
             subMenu2[i].addActionListener(this);
             mainMenu2.add(subMenu2[i]);
         }
         menuBar.add(mainMenu2);
/////////////////////////////////////////////////
         mainMenu3 = new JMenu("帮助");
         String str3[] = {"帮助...","关于..."};
         for(int i=0;i<2;i++)
         {
             subMenu3[i] = new JMenuItem(str3[i]);
             subMenu3[i].addActionListener(this);
             mainMenu3.add(subMenu3[i]);
          }
          menuBar.add(mainMenu3);
////////////////////////////////////////////////
          String strToolBar[] ={"查询","添加","删除","修改","保存","浏览","退出"};

         for(int i=0;i<7;i++)
         {

              toolBarButton[i] = new JButton(strToolBar[i]);
              toolBarButton[i].setToolTipText(strTip[i]);
              toolBarButton[i].addActionListener(this);
              toolBar.add(toolBarButton[i]);

          }
          toolBarButton[4].setEnabled(false);
          toolBar.setLocation(0,0);
          toolBar.setSize(400,30);
          c.add(toolBar);
////////////////////////////////////////////////
          idL.setLocation(35,40);
          idL.setSize(40,20);
          c.add(idL);

          idT.setLocation(110,40);
          idT.setSize(200,20);
          idT.setEnabled(false);
          c.add(idT);

          nameL.setLocation(35,70);
          nameL.setSize(40,20);
          c.add(nameL);

          nameT.setLocation(110,70);
          nameT.setSize(200,20);
          c.add(nameT);

          xbL.setLocation(35,100);
          xbL.setSize(40,20);
          c.add(xbL);

          xbT.setLocation(110,100);
          xbT.setSize(200,20);
          c.add(xbT);

          dwL.setLocation(35,130);
          dwL.setSize(40,20);
          c.add(dwL);

          dwT.setLocation(110,130);
          dwT.setSize(200,20);
          c.add(dwT);

         dh1L.setLocation(35,160);
         dh1L.setSize(60,20);
         c.add(dh1L);

         dh1T.setLocation(110,160);
         dh1T.setSize(200,20);
         c.add(dh1T);

         dh2L.setLocation(35,190);
         dh2L.setSize(60,20);
         c.add(dh2L);

         dh2T.setLocation(110,190);
         dh2T.setSize(200,20);
         c.add(dh2T);

         zwL.setLocation(35,220);
         zwL.setSize(40,20);
         c.add(zwL);

         zwT.setLocation(110,220);
         zwT.setSize(200,20);
         c.add(zwT);
         
         emailL.setLocation(35,250);
         emailL.setSize(80,20);
         c.add(emailL);

         emailT.setLocation(110,250);
         emailT.setSize(200,20);
         c.add(emailT);
         
         dzL.setLocation(35,280);
         dzL.setSize(40,20);
         c.add(dzL);

         dzT.setLocation(110,280);
         dzT.setSize(200,20);
         c.add(dzT);
         
         ybL.setLocation(35,310);
         ybL.setSize(40,20);
         c.add(ybL);

         ybT.setLocation(110,310);
         ybT.setSize(200,20);
         c.add(ybT);
         
         next.setLocation(150,350);
         next.setSize(80,20);
         next.addActionListener(this);
         next.setVisible(false);
         c.add(next);
            idT.setEnabled(false);
            nameT.setEnabled(false);
            xbT.setEnabled(false);
            dwT.setEnabled(false);
            dh1T.setEnabled(false);
            dh2T.setEnabled(false);
            zwT.setEnabled(false);
            emailT.setEnabled(false);
            dzT.setEnabled(false);
            ybT.setEnabled(false);
/////////////////////////////////////////////////

         JLabel information = new JLabel("样例程序");
         information.setFont(new Font("宋体",Font.BOLD,24));
         information.setSize(200,110);
         information.setLocation(10,320);
         c.add(information);
////////////////////////////////////////////////
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.setSize(400,450);
         frame.setVisible(true);
         bz=0;

         conDB();
    }
    //以上是设置数据库面版、框架(构造函数)
    //以下是连接数据库
    public void conDB()
    {
      try
      {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

       }
      catch(ClassNotFoundException e)
       {
          JOptionPane.showMessageDialog(null,"数据库加载失败了!");
       }
      try
       {
          con = DriverManager.getConnection("jdbc:odbc:zht","","");
          st = con.createStatement();
        }
       catch(SQLException e)
       {
           JOptionPane.showMessageDialog(null,"数据库连接失败!");
        }

    }
     //以下是关闭数据库
     public void closeDB()
     {
        try
        {
            st.close();
            con.close();
        }
        catch(SQLException e )
        {
            JOptionPane.showMessageDialog(null,"数据库关闭失败!");
         }
     }
       //以下是针对数据库的各种操作,单击事件处理
     public void actionPerformed(ActionEvent e)
     {
     	if( e.getSource()==toolBarButton[5])  //浏览记录
     	{
     		next.setVisible(true);
     		String strSQL = "select * from user_1";
                  try
                  {
                  rs = st.executeQuery(strSQL);
                      if(rs.next())
                       {
                             id = rs.getString("id");
                             name = rs.getString("name");
                             xb=rs.getString("xb");
                             dw=rs.getString("dw");
                             dh1=rs.getString("dh1");
                             dh2=rs.getString("dh2");
                             zw=rs.getString("zw");
                             email=rs.getString("email");
                             dz=rs.getString("dz");
                             yb=rs.getString("yb");
                        }
                        else
                        {
                             JOptionPane.showMessageDialog(null,"对不起,没有您要查找客户");
                        }
                             idT.setText(id);
                             nameT.setText(name);
                             xbT.setText(xb);
                             dwT.setText(dw);
                             dh1T.setText(dh1);
                             dh2T.setText(dh2);
                             zwT.setText(zw);
                             emailT.setText(email);
                             dzT.setText(dz);
                             ybT.setText(yb);
            nameT.setEnabled(false);
            xbT.setEnabled(false);
            dwT.setEnabled(false);
            dh1T.setEnabled(false);
            dh2T.setEnabled(false);
            zwT.setEnabled(false);
            emailT.setEnabled(false);
            dzT.setEnabled(false);

⌨️ 快捷键说明

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