📄 student_java_db
字号:
import java.io.*;import java.applet.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class menu extends Frame implements WindowListener,ActionListener{MenuBar mb;MenuItem student,rollnowise,namewise,allresult;public static menu m;rollnowise rw;namewise n;student st;int x,y,d;public menu() { super("menu ARPAN"); addWindowListener(this); x=y=700; d=10; setSize(x,y); setBackground(Color.orange); addMenu(); show(); } public static void main(String args[]) { m=new menu(); }void addMenu() { MenuBar mb=new MenuBar(); Menu register=new Menu("REGISTER"); Menu inquery=new Menu("INQUERY"); register.add("STUDENT"); register.add("EXIT"); inquery.add("ROLLNOWISE"); inquery.add("NAMEWISE"); mb.add(register); mb.add(inquery); setMenuBar(mb); register.addActionListener(this); inquery.addActionListener(this); }public void actionPerformed(ActionEvent ae) { String arg=ae.getActionCommand(); if(ae.getSource() instanceof Menu) if(arg.equals("EXIT")) { System.exit(0); } if(ae.getSource() instanceof Menu) if("STUDENT".equals(arg)) { st=new student(); st.show(); } if(ae.getSource() instanceof Menu) if("ROLLNOWISE".equals(arg)) { rw=new rollnowise(); rw.show(); } if(ae.getSource() instanceof Menu) if("NAMEWISE".equals(arg)) { n=new namewise(); n.show(); } }public void windowClosed(WindowEvent we){}public void windowDeiconified(WindowEvent we){}public void windowIconified(WindowEvent we){}public void windowActivated(WindowEvent we){}public void windowDeactivated(WindowEvent we){}public void windowOpened(WindowEvent we){}public void windowClosing(WindowEvent we) { while(x>0 && y>0) { setSize(x,y); x=x-d; y=y-d; show(); } System.out.println("mail me at arpankumarsingh@yahoo.com"); dispose(); System.exit(0); }}//class for name wise reportclass namewise extends Frame implements WindowListener,ActionListener { public static namewise nw; Label l1=new Label("NAME",Label.LEFT); Label l2=new Label("ROLLNO",Label.LEFT); Label l3=new Label("COLG",Label.LEFT); Label l4=new Label("SUB1",Label.LEFT); Label l5=new Label("SUB2",Label.LEFT); Label l6=new Label("SUB3",Label.LEFT); Label l7=new Label("SUB4",Label.LEFT); Label l8=new Label("SUB5",Label.LEFT); TextField tf_entername=new TextField(20); Button but_entername =new Button("FIND"); Button ok=new Button("OK"); Graphics g; String sqlstr; Statement st; GridLayout gl=new GridLayout(1,2); GridLayout cl=new GridLayout(1,5); Font font18=new Font("VinetaBT",Font.BOLD|Font.ITALIC,18); int x,y,d; Dialog dlg; Label msg; public namewise() { super("NAMEWISE"); addWindowListener(this); setLayout(new GridLayout(12,1)); setBackground(Color.orange); setForeground(Color.black); addMenu(); x=550; y=450; d=100; setSize(x,y); show(); } void addMenu() { Panel p4=new Panel(); Label l11=new Label("ENTERNAME"); p4.add(l11); p4.add(tf_entername); p4.add(but_entername); add(p4); but_entername.addActionListener(this); ok.addActionListener(this); //Dialog for confirmation dlg=new Dialog(this,"Inventory Management System",false); dlg.setLayout(new GridLayout(2,1)); dlg.setSize(100,100); dlg.setLocation(200,100); ok.setSize(50,50); msg=new Label("NAME NOT FOUND"); dlg.add(msg); dlg.add(ok); } public void actionPerformed(ActionEvent e) { Panel p1=new Panel(); l1.setFont(font18); l2.setFont(font18); p1.setLayout(gl); p1.add(l1); p1.add(l2); g=getGraphics(); g.drawLine(40,0,40,0); Panel p2=new Panel(); l3.setFont(font18); p2.add(l3); p2.setLayout(gl); Panel p3=new Panel(); l4.setFont(font18); l5.setFont(font18); l6.setFont(font18); l7.setFont(font18); l8.setFont(font18); p3.add(l4); p3.add(l5); p3.add(l6); p3.add(l7); p3.add(l8); p3.setLayout(cl); String arg=e.getActionCommand(); if(e.getSource() instanceof Button) if("FIND".equals(arg)) try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:stu","",""); sqlstr="select * from stu1 where NAME='"+tf_entername.getText()+"'"; st=con.createStatement(); ResultSet rs; rs= st.executeQuery(sqlstr); while(rs.next()) { Panel a1=new Panel(); l1=new Label("",Label.LEFT); l2=new Label("",Label.LEFT); l1.setFont(font18); l2.setFont(font18); a1.setLayout(gl); Panel a2=new Panel(); l3=new Label("",Label.LEFT); l3.setFont(font18); a2.setLayout(gl); Panel a3=new Panel(); l4=new Label("",Label.LEFT); l5=new Label("",Label.LEFT); l6=new Label("",Label.LEFT); l7=new Label("",Label.LEFT); l8=new Label("",Label.LEFT); l4.setFont(font18); l5.setFont(font18); l6.setFont(font18); l7.setFont(font18); l8.setFont(font18); a3.setLayout(cl); l1.setText(rs.getString("NAME")); l2.setText(""+rs.getInt("ROLLNO")); l3.setText(rs.getString("COLG")); l4.setText(""+rs.getInt("SUB1")); l5.setText(""+rs.getInt("SUB2")); l6.setText(""+rs.getInt("SUB3")); l7.setText(""+rs.getInt("SUB4")); l8.setText(""+rs.getInt("SUB5")); a1.add(l1); a1.add(l2); a2.add(l3); a3.add(l4); a3.add(l5); a3.add(l6); a3.add(l7); a3.add(l8); add(p1); add(a1); add(p2); add(a2); add(p3); add(a3); show(); } } catch(ClassNotFoundException se) { tf_entername.setText("Error : " + se.toString()); } catch(SQLException se) { tf_entername.setText("Error : " + se.toString()); } }public void windowClosed(WindowEvent we){}public void windowDeiconified(WindowEvent we){}public void windowIconified(WindowEvent we){}public void windowActivated(WindowEvent we){}public void windowDeactivated(WindowEvent we){}public void windowOpened(WindowEvent we){}public void windowClosing(WindowEvent we) { while(x>0 && y>0) { setSize(x,y); x=x-d; y=y-d; show(); } dispose();}}//class for rollnowise report class rollnowise extends Frame implements WindowListener,ActionListener { public static rollnowise rw; Label l1=new Label("NAME",Label.LEFT); Label l2=new Label("ROLLNO",Label.LEFT); Label l3=new Label("COLG",Label.LEFT); Label l4=new Label("SUB1",Label.LEFT); Label l5=new Label("SUB2",Label.LEFT); Label l6=new Label("SUB3",Label.LEFT); Label l7=new Label("SUB4",Label.LEFT); Label l8=new Label("SUB5",Label.LEFT); TextField tf_entername=new TextField(20); Button but_entername =new Button("FIND"); String sqlstr; Statement st; GridLayout gl=new GridLayout(1,2); GridLayout cl=new GridLayout(1,5); Font font18=new Font("VinetaBT",Font.BOLD|Font.ITALIC,18); int x,y,d; public rollnowise() { super("ROLLNOWISE"); addWindowListener(this); setLayout(new GridLayout(12,1)); setBackground(Color.orange); setForeground(Color.black); addMenu(); x=550; y=450; d=100; setSize(x,y); show(); } void addMenu() { Panel p4=new Panel(); Label l11=new Label("ENTERROLLNO"); p4.add(l11); p4.add(tf_entername); p4.add(but_entername); add(p4); but_entername.addActionListener(this); } public void actionPerformed(ActionEvent e){ Panel p1=new Panel(); l1.setFont(font18); l2.setFont(font18); p1.setLayout(gl); p1.add(l1); p1.add(l2); l3.setFont(font18); Panel p2=new Panel(); p2.add(l3); p2.setLayout(gl); Panel p3=new Panel(); l4.setFont(font18); l5.setFont(font18); l6.setFont(font18); l7.setFont(font18); l8.setFont(font18); p3.add(l4); p3.add(l5); p3.add(l6); p3.add(l7); p3.add(l8);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -