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

📄 frame1.java~23~

📁 数据库管理系统平台
💻 JAVA~23~
📖 第 1 页 / 共 2 页
字号:
package 教学系统;

import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JTabbedPane;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import javax.swing.border.EtchedBorder;
import javax.swing.border.Border;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import javax.swing.table.TableModel;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.ResultSetMetaData;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Frame1 extends JFrame {
    Connection connect;
    JPanel contentPane;
    DefaultTableModel defaultTableModel1=new DefaultTableModel();
    DefaultTableModel defaultTableModel2=new DefaultTableModel();
    JMenuBar jMenuBar1 = new JMenuBar();
    JMenu jMenuFile = new JMenu();
    JMenuItem jMenuFileExit = new JMenuItem();
    JMenu jMenuHelp = new JMenu();
    JMenuItem jMenuHelpAbout = new JMenuItem();
    JTabbedPane jTabbedPane1 = new JTabbedPane();
    XYLayout xYLayout1 = new XYLayout();
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    XYLayout xYLayout2 = new XYLayout();
    JPanel jPanel3 = new JPanel();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JButton jButton3 = new JButton();
    JButton jButton4 = new JButton();
    GridLayout gridLayout1 = new GridLayout();
    JPanel jPanel4 = new JPanel();
    XYLayout xYLayout3 = new XYLayout();
    Border border1 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
            Color.cyan, new Color(165, 163, 151));
    Border border2 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
            Color.white, new Color(165, 163, 151));
    Border border3 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
            Color.cyan, new Color(165, 163, 151));
    JScrollPane jScrollPane1 = new JScrollPane();
    Border border4 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
            Color.white, new Color(165, 163, 151));
    JTable jTable1 = new JTable();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JLabel jLabel4 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JTextField jTextField2 = new JTextField();
    JTextField jTextField3 = new JTextField();
    JTextField jTextField4 = new JTextField();
    JPanel jPanel5 = new JPanel();
    XYLayout xYLayout4 = new XYLayout();
    GridLayout gridLayout2 = new GridLayout();
    JButton jButton5 = new JButton();
    JButton jButton6 = new JButton();
    JButton jButton7 = new JButton();
    JButton jButton8 = new JButton();
    JPanel jPanel6 = new JPanel();
    Border border5 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
            Color.cyan, new Color(165, 163, 151));
    JScrollPane jScrollPane2 = new JScrollPane();
    JTable jTable2 = new JTable();
    Border border7 = BorderFactory.createLineBorder(Color.cyan, 2);
    Border border6 = BorderFactory.createLineBorder(Color.cyan, 2);
    JLabel jLabel5 = new JLabel();
    JLabel jLabel6 = new JLabel();
    XYLayout xYLayout5 = new XYLayout();
    JLabel jLabel7 = new JLabel();
    JLabel jLabel8 = new JLabel();
    JTextField jTextField5 = new JTextField();
    JTextField jTextField6 = new JTextField();
    JTextField jTextField7 = new JTextField();
    JTextField jTextField8 = new JTextField();
    Border border8 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
            Color.cyan, new Color(165, 163, 151));
    JPanel jPanel7 = new JPanel();
    XYLayout xYLayout6 = new XYLayout();
    JPanel jPanel8 = new JPanel();
    Border border9 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
            Color.green, new Color(165, 163, 151));
    JPanel jPanel9 = new JPanel();
    Border border10 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
            Color.green, new Color(165, 163, 151));
    JPanel jPanel10 = new JPanel();
    XYLayout xYLayout7 = new XYLayout();
    XYLayout xYLayout8 = new XYLayout();
    JButton jButton9 = new JButton();
    JButton jButton10 = new JButton();
    GridLayout gridLayout3 = new GridLayout();
    JPanel jPanel11 = new JPanel();
    JButton jButton11 = new JButton();
    JButton jButton12 = new JButton();
    GridLayout gridLayout4 = new GridLayout();
    JLabel jLabel9 = new JLabel();
    JLabel jLabel10 = new JLabel();
    JLabel jLabel11 = new JLabel();
    JLabel jLabel12 = new JLabel();
    JLabel jLabel13 = new JLabel();
    JTextField jTextField9 = new JTextField();
    JTextField jTextField10 = new JTextField();
    JTextField jTextField11 = new JTextField();
    JTextField jTextField12 = new JTextField();
    JTextField jTextField13 = new JTextField();
    public Frame1() {
        try {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    /**
     * Component initialization.
     *
     * @throws java.lang.Exception
     */
    private void jbInit() throws Exception {
        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(xYLayout1);
        setSize(new Dimension(600, 450));
        setTitle("教学系统");
        jMenuFile.setText("File");
        jMenuFileExit.setText("Exit");
        jMenuFileExit.addActionListener(new Frame1_jMenuFileExit_ActionAdapter(this));
        jMenuHelp.setText("Help");
        jMenuHelpAbout.setText("About");
        jMenuHelpAbout.addActionListener(new
                                         Frame1_jMenuHelpAbout_ActionAdapter(this));
        jPanel1.setLayout(xYLayout2);
        jPanel3.setBackground(new Color(203, 255, 255));
        jPanel3.setLayout(gridLayout1);
        jButton1.setBackground(new Color(215, 249, 241));
        jButton1.setText("查询");
        jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
        jButton2.setText("插入");
        jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
        jButton3.setText("删除");
        jButton3.addActionListener(new Frame1_jButton3_actionAdapter(this));
        jButton4.setText("清空");
        jButton4.addActionListener(new Frame1_jButton4_actionAdapter(this));
        jPanel4.setLayout(xYLayout3);
        jScrollPane1.setBorder(border6);
        jLabel1.setText("教   号");
        jLabel2.setText("姓   名");
        jLabel3.setText("性   别");
        jLabel4.setText("地   止");
        jTextField1.setText("");
        jTextField2.setText("");
        jTextField3.setText("");
        jTextField4.setText("");
        jPanel2.setLayout(xYLayout4);
        jPanel5.setLayout(gridLayout2);
        jButton5.setText("查询");
        jButton5.addActionListener(new Frame1_jButton5_actionAdapter(this));
        jButton6.setText("插入");
        jButton6.addActionListener(new Frame1_jButton6_actionAdapter(this));
        jButton7.setText("删除");
        jButton7.addActionListener(new Frame1_jButton7_actionAdapter(this));
        jButton8.setText("清空");
        jButton8.addActionListener(new Frame1_jButton8_actionAdapter(this));
        jPanel6.setBorder(border5);
        jPanel6.setLayout(xYLayout5);
        jScrollPane2.setBorder(border7);
        jLabel5.setText("学   号");
        jLabel6.setText("姓   名");
        jLabel7.setText("性   别");
        jLabel8.setText("寝室号");
        jPanel4.setBorder(border8);
        jPanel7.setLayout(xYLayout6);
        jPanel8.setBorder(border9);
        jPanel8.setLayout(xYLayout7);
        jPanel9.setBorder(border10);
        jPanel9.setLayout(xYLayout8);
        jButton9.setText("插入");
        jButton10.setText("清空");
        jPanel10.setLayout(gridLayout3);
        jButton11.setText("插入");
        jButton12.setText("清空");
        jPanel11.setLayout(gridLayout4);
        jLabel9.setText("jLabel9");
        jLabel10.setText("jLabel10");
        jLabel11.setText("jLabel11");
        jLabel12.setText("jLabel12");
        jLabel13.setText("jLabel13");
        jTextField9.setText("jTextField9");
        jTextField10.setText("jTextField10");
        jTextField11.setText("jTextField11");
        jTextField12.setText("jTextField12");
        jTextField13.setText("jTextField13");
        jMenuBar1.add(jMenuFile);
        jMenuFile.add(jMenuFileExit);
        jMenuBar1.add(jMenuHelp);
        jMenuHelp.add(jMenuHelpAbout);
        contentPane.add(jTabbedPane1, new XYConstraints(0, 0, 600, 448));
        jPanel2.add(jPanel5, new XYConstraints(50, 18, 491, 41));
        jPanel3.add(jButton1, null);
        jPanel3.add(jButton2, null);
        jPanel3.add(jButton3, null);
        jPanel3.add(jButton4, null);
        jPanel1.add(jPanel3, new XYConstraints(44, 13, 471, 40));
        jPanel1.add(jPanel4, new XYConstraints(9, 61, 281, 354));
        jPanel4.add(jLabel1, new XYConstraints(7, 20, 52, 25));
        jPanel1.add(jScrollPane1, new XYConstraints(302, 60, 270, 356));
        jPanel4.add(jLabel2, new XYConstraints(7, 89, 52, 25));
        jPanel4.add(jLabel3, new XYConstraints(7, 174, 52, 25));
        jPanel4.add(jLabel4, new XYConstraints(7, 249, 52, 25));
        jPanel4.add(jTextField1, new XYConstraints(61, 16, 144, 29));
        jPanel4.add(jTextField2, new XYConstraints(61, 85, 144, 29));
        jPanel4.add(jTextField3, new XYConstraints(61, 170, 144, 29));
        jPanel4.add(jTextField4, new XYConstraints(61, 245, 144, 29));
        jPanel5.add(jButton5);
        jPanel5.add(jButton6);
        jPanel5.add(jButton7);
        jPanel5.add(jButton8);
        jPanel2.add(jPanel6, new XYConstraints(19, 86, 245, 321));
        jPanel2.add(jScrollPane2, new XYConstraints(307, 87, 236, 318));
        jScrollPane2.getViewport().add(jTable2);
        jScrollPane1.getViewport().add(jTable1);
        jPanel6.add(jLabel5, new XYConstraints(17, 20, 51, 26));
        jPanel6.add(jLabel6, new XYConstraints(17, 101, 51, 26));
        jPanel6.add(jLabel7, new XYConstraints(17, 178, 51, 26));
        jPanel6.add(jLabel8, new XYConstraints(17, 248, 51, 26));
        jPanel6.add(jTextField5, new XYConstraints(75, 14, 125, 32));
        jPanel6.add(jTextField6, new XYConstraints(75, 95, 125, 32));
        jPanel6.add(jTextField7, new XYConstraints(75, 172, 125, 32));
        jPanel6.add(jTextField8, new XYConstraints(75, 242, 125, 32));
        jTabbedPane1.add(jPanel1, "教师系统");
        jTabbedPane1.add(jPanel2, "学生系统");
        jTabbedPane1.add(jPanel7, "课程更新");
        jPanel7.add(jPanel8, new XYConstraints(15, 16, 282, 404));
        jPanel8.add(jPanel10, new XYConstraints(33, 10, 190, 35));
        jPanel10.add(jButton9);
        jPanel10.add(jButton10);
        jPanel7.add(jPanel9, new XYConstraints(299, 16, 282, 404));
        jPanel9.add(jPanel11, new XYConstraints(42, 12, 179, 35));
        jPanel11.add(jButton11, null);
        jPanel11.add(jButton12, null);
        jPanel9.add(jLabel12, new XYConstraints(32, 77, 65, 32));
        jPanel8.add(jLabel9, new XYConstraints(24, 84, 66, 27));
        jPanel8.add(jLabel11, new XYConstraints(24, 197, 66, 27));
        jPanel8.add(jTextField9, new XYConstraints(96, 87, 130, 29));
        jPanel8.add(jTextField10, new XYConstraints(96, 139, 130, 29));
        jPanel8.add(jTextField11, new XYConstraints(96, 195, 130, 29));
        jPanel8.add(jLabel10, new XYConstraints(24, 141, 66, 27));
        jPanel9.add(jLabel13, new XYConstraints(32, 127, 65, 32));
        jPanel9.add(jTextField12, new XYConstraints(98, 80, 135, 34));
        jPanel9.add(jTextField13, new XYConstraints(98, 126, 135, 34));
        setJMenuBar(jMenuBar1);
        try
        {
          String url="jdbc:odbc:wang";
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          connect=DriverManager.getConnection(url,"root","abc");
        }
        catch   (SQLException   sqlex)
         {
            System.err.println("unable   to   connect");
            sqlex.printStackTrace();
        }


    }

    /**
     * File | Exit action performed.
     *
     * @param actionEvent ActionEvent
     */
    void jMenuFileExit_actionPerformed(ActionEvent actionEvent) {
        System.exit(0);
    }

    /**
     * Help | About action performed.
     *
     * @param actionEvent ActionEvent
     */
    void jMenuHelpAbout_actionPerformed(ActionEvent actionEvent) {
        Frame1_AboutBox dlg = new Frame1_AboutBox(this);
        Dimension dlgSize = dlg.getPreferredSize();
        Dimension frmSize = getSize();
        Point loc = getLocation();
        dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                        (frmSize.height - dlgSize.height) / 2 + loc.y);
        dlg.setModal(true);
        dlg.pack();
        dlg.show();
    }

    void message(String t)
      {
          JOptionPane.showMessageDialog(null,t);
      }


    public void jButton1_actionPerformed(ActionEvent e) {
        try
        {
            Statement statement =connect.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,
                                    ResultSet.CONCUR_UPDATABLE);
             String query1="select * from teacher where tssn="+"'"+jTextField1.getText()+"'";
             String query2="select * from  tsubject where   tssn='"
                           +jTextField1.getText()+"'";
             ResultSet rs1 = statement.executeQuery( query1 );
             if(rs1.next())
             {
                     jTextField2.setText( rs1.getString( "tname" ) );
                     jTextField3.setText( rs1.getString( "sex" ) );
                     jTextField4.setText( rs1.getString( "adress" ) );

             }
             else
             {

                String find="查无此人";
                message(find);
             }
             statement=connect.createStatement();
             rs1=statement.executeQuery(query2);
             ResultSetMetaData rsmd1=rs1.getMetaData();
             defaultTableModel1.setColumnCount(0);
             defaultTableModel1.setRowCount(0);
             for(int i=1;i<=rsmd1.getColumnCount();i++)
              {
                    defaultTableModel1.addColumn(rsmd1.getColumnName(i));
              }
             int i=0;
             while(rs1.next())
               {
                     defaultTableModel1.setNumRows(i+1);
                     for (int j=0;j<rsmd1.getColumnCount();j++)
                         {
                             defaultTableModel1.setValueAt(rs1.getString(j+1),i,j);
                         }
                     i++;
             }
            rs1.close();
            jTable1.setModel((TableModel)defaultTableModel1);

⌨️ 快捷键说明

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