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

📄 yw.java~4~

📁 JAVA实验图形 =各种 的 JAVA简单代码 出初学者必备!!!!!!!!!
💻 JAVA~4~
字号:
package yw321;import java.io.*;import java.sql.*;import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.table.*;import java.awt.Frame;public class yw extends JFrame   { static String s;    public static void main(String args[])    {yw y=new yw();  y.y1();    }        TextField b2=new TextField();        TextField b3=new TextField();        TextField b4=new TextField();        TextField b5=new TextField();       String num1;       public static int sn;       public static String sna;       AbstractTableModel tm;        JTable table;    JScrollPane scollpane;    String titles[];    Vector records;     public void jie(){         String sql = "select * from stubook;";         yw f=new yw();                         f.init();                  Label b0=new Label("学号:"+b2.getText()+"     姓名:"+b3.getText()+"     申请书名:"+b4.getText()+"      申请数量:"+b5.getText());                  f.add(b0);                   try{                             f.start(sql);                         }                         catch(Exception e){e.printStackTrace();}                 f.setSize(400,100);                 f.setTitle("数据库查询");                 f.setVisible(true); }    public void chaxun()                {                 String sql = "select * from stubook;";                   yw f=new yw();                    f.init();                    try{                        f.start(sql);}                    catch(Exception e){e.printStackTrace();}            f.setSize(400,300);            f.setTitle("数据库查询");            f.setVisible(true);        }        public void chaxun2()               {                   String sql = "select * from book;";                   yw f=new yw();                  f.init();                  try{                       f.start(sql);}                   catch(Exception e){e.printStackTrace();}           f.setSize(500,500);           f.setTitle("数据库查询");           f.setVisible(true);         }         public void xiugai()         {       String str = "update student set sno=123 where sno=123;";             yw f=new yw();      f.init();  try{              f.start(str);}           catch(Exception e2){e2.printStackTrace();}           f.setSize(300,300);                     f.setTitle("数据库查询444");                     f.setVisible(true); chaxun();         }         public void xiugai2()      {    String str = "update book set bno=123 where bno=1;";          yw f=new yw();   f.init();try{           f.start(str);}        catch(Exception e2){e2.printStackTrace();}        f.setSize(300,300);                  f.setTitle("数据库查询444");                  f.setVisible(true); chaxun2();      }public void delete()      { String str = "delete from student  where sno=1;";          yw f=new yw();   f.init();try{           f.start(str);}        catch(Exception e2){e2.printStackTrace();}        f.setSize(300,300);                  f.setTitle("数据库查询444");                  f.setVisible(true); chaxun2();              }public void delete2()              { String str = "delete from book where bno=1;";                  yw f=new yw();           f.init();        try{                   f.start(str);}                catch(Exception e2){e2.printStackTrace();}                f.setSize(300,300);                          f.setTitle("数据库查询444");                          f.setVisible(true); chaxun2();              }  public void y1()        {{            Button bb=new Button("确定");            Frame e=new Frame();  e.setSize(600,600);e.setBackground(Color.blue);            e.setTitle("教材购销管理系统 ");e.add(bb);            e.setVisible(true);           Label pan=new Label("欢迎使用教材购销管理系统");           Font w=new Font("TimesRoman",Font.CENTER_BASELINE,20);           b4.setSize(100,20);          b4.setEditable(true);          b4.setText("书名"); b4.setVisible(true);          b5.setSize(100,20);b4.setLocation(50,350);                          b5.setEditable(true);b5.setLocation(300,350);          b5.setText("数量"); b5.setVisible(true);e.add(b4);e.add(b5);          b2.setSize(100,20);          b2.setEditable(true);          b2.setText("学号"); b2.setVisible(true);           e.add(b2);b2.setLocation(50,300);bb.setSize(80,20);bb.setVisible(true);          e.add(bb);bb.setLocation(450,300);          b3.setSize(100,20);          b3.setEditable(true);          b3.setText("姓名"); b3.setVisible(true);          pan.setFont(w);pan.setVisible(true);  pan.setSize(300,200);pan.setVisible(true);          pan.setLocation(150,50);e.add(pan);          e.add(b3);b3.setLocation(300,300);          String str = "update student set sno="+b2.getText()+" ,sname=' "+b3.getText()+"'where sno=6;";          boolean a=true;  if(a=false)       {           yw f=new yw();       f.init();       try{                              f.start(str);}                         catch(Exception e2){e2.printStackTrace();}     System.out.println("1231231231"); f.setSize(500,500);      f.setTitle("数据库查询456");      f.setVisible(true);}      MenuBar mb=new MenuBar();           Menu m1=new  Menu("申请教材");          Menu m2=new Menu("查看借阅历史");          Menu m3=new Menu("离开教材购销管理系统"); Menu m4=new Menu("修改");MenuItem m11=new MenuItem("借阅图书登记");          MenuItem m21=new MenuItem("查看学生记录");Menu m5=new Menu("删除");           MenuItem m22=new MenuItem("查看藏书");  MenuItem m41=new MenuItem("修改学生记录");  MenuItem m42=new MenuItem("修改藏书记录");         m1.add(m11);  m2.add(m21); m2.add(m22);m4.add(m41);         MenuItem m51=new MenuItem("删除学生记录");  MenuItem m52=new MenuItem("删除藏书记录");        m4.add(m42);m5.add(m51);m5.add(m52); e.setMenuBar(mb); m11.addActionListener(new ActionListener(){          public void actionPerformed(ActionEvent e){              jie(); }});bb.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){    jie();  num1=b2.getText();System.out.println(""+num1);}});m41.addActionListener(new ActionListener(){                  public void actionPerformed(ActionEvent e){                      xiugai(); }});m51.addActionListener(new ActionListener(){                            public void actionPerformed(ActionEvent e){                     delete(); }});         m42.addActionListener(new ActionListener(){                public void actionPerformed(ActionEvent e){                    xiugai2(); }}); m52.addActionListener(new ActionListener(){                          public void actionPerformed(ActionEvent e){                    delete2(); }});         m11.addActionListener(new ActionListener(){                   public void actionPerformed(ActionEvent e){              jie(); }});          m21.addActionListener(new ActionListener(){           public void actionPerformed(ActionEvent e){            chaxun(); }});          m22.addActionListener(new ActionListener(){              public void actionPerformed(ActionEvent e){            chaxun2();  }});           mb.add(m1);           mb.add(m2);mb.add(m4);mb.add(m5);           mb.setHelpMenu(m3); e.addWindowListener(                new WindowAdapter(){            public void windowClosing(WindowEvent e)            {                System.exit(0);            }});} }public void init(){        records=new Vector();        tm=new AbstractTableModel(){            public int getColumnCount(){            return titles.length;//取得表格列数            }            public int getRowCount(){                return records.size();//取得表格行数            }public Object getValueAt(int row,int column){            if(!records.isEmpty()) //取得单元格中的属性值                    return ((Vector)records.elementAt(row)).elementAt(column);            else return null;            }public String getColumnName(int column){                return titles[column];}            public void setValueAt(Object value,int row,int column){}            public Class getColumnClass(int c){            return getValueAt(0,c).getClass();            }            public boolean isCellEditable(int row,int column){            return false;            }};}    public  void start(String sql) throws SQLException{          try{ Statement stmt;                PreparedStatement pstmt;                ResultSet rs;                //加载JDBC-ODBC桥驱动                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");                //定义JDBC URL             String url="jdbc:odbc:syuewei";                //得到与数据库的连接              Connection con=DriverManager.getConnection(url,"system","sys");                //显示UPL和连接信息                  System.out.println("URL:"+url);                  System.out.println("Connection:"+con);                  //得到一个Statement对象                  stmt=con.createStatement();                  //执行SQL语句                  ResultSet p = stmt.executeQuery(sql);                  ResultSetMetaData meta =p.getMetaData();                  int cols=meta.getColumnCount();                  System.out.println(cols);                  titles=new String[cols];                  for(int i=0;i<cols;i++){                      titles[i]=meta.getColumnName(i+1);                  }                  records.removeAllElements();                  while(p.next()){                      Vector rec_vector = new Vector();                     for(int i=0;i<cols;i++){rec_vector.addElement(p.getObject(i+1).toString());                     }records.addElement(rec_vector);                  }                  table=new JTable(tm);//生成自己的数据模型                  table.setToolTipText("显示所有查询结果");                  table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);//设置表格调整尺寸                  table.setCellSelectionEnabled(false);//设置单元格选择方式                  table.setShowVerticalLines(true);                  table.setShowHorizontalLines(true);                  scollpane=new JScrollPane(table);        add(scollpane);                  tm.fireTableStructureChanged();//打印测试}catch(Exception e){}         }}

⌨️ 快捷键说明

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