boxH3.add(box5); boxH3.add(box7);
boxH3.add(Box.createVerticalGlue()); 查找.addActionListener(this); 查找1.addActionListener(this); 查找2.addActionListener(this); JPanel messPanel=new JPanel(); JPanel picPanel=new JPanel(); JPanel threePanel=new JPanel(); messPanel.add(boxH1); picPanel.add(boxH2); threePanel.add(boxH3);
setLayout(new BorderLayout()); JSplitPane splitV=new
JSplitPane(JSplitPane.VERTICAL_SPLIT,messPanel,picPanel);//分割 add(splitV,BorderLayout.CENTER);
JSplitPane splitV1=new
JSplitPane(JSplitPane.VERTICAL_SPLIT,splitV,threePanel);//分割 add(splitV1,BorderLayout.CENTER);
validate();}
效果图:
下面是java的源代码,总共有15个类。分别是AddC.java,AddSC.java,Addstu.java, Delstu.java,DelC.java, DelSC.java,Menu.java,SelC.java,SelSC.java,Selstu.java,Student.java,Updatastu.java,UpdateC.java,UpdateSC.java,User.java。
因为本人太懒,所以一些类名的错误没有修改,也没有优化系统,总之还算是能运行的,数据库用的是sql2005,如果用别的数据库就要改驱动,具体自己上网百度吧。如果自己有空,优化一下还是很好滴……
AddC.jaba:
import java.awt.*; import javax.swing.*; import java.sql.*;
import java.awt.event.*;
public class AddC extends JPanel implements ActionListener{ JTextField 课号,课名; JButton 录入;
public AddC(){ try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} catch(Exception e){System.err.println(\不能设置外观: \ 课号=new JTextField(12); 课名=new JTextField(12); 录入=new JButton(\录入\ 录入.addActionListener(this); Box box1=Box.createHorizontalBox();//横放box Box box2=Box.createHorizontalBox(); Box box3=Box.createHorizontalBox(); Box box4=Box.createHorizontalBox(); box1.add(new JLabel(\课号:\ box1.add(课号); box2.add(new JLabel(\课名:\ box2.add(课名); box4.add(录入); Box boxH=Box.createVerticalBox();//竖放box boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(Box.createVerticalGlue());
JPanel messPanel=new JPanel(); messPanel.add(boxH); setLayout(new BorderLayout()); add(messPanel,BorderLayout.CENTER); validate(); }
public void actionPerformed(ActionEvent c){ Object obj=c.getSource(); if(obj==录入){ if(课号.getText().equals(\课名.getText().equals(\ JOptionPane.showMessageDialog(this,\学生信息请填满再录入!\ } Statement stmt=null; ResultSet rs=null,rs1=null; String sql,sql1; sql1=\课号.getText()+\ sql=\课号.getText()+\课名.getText()+\ try{ Connection dbConn1=CONN(); stmt=(Statement)dbConn1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); rs1=stmt.executeQuery(sql1); if(rs1.next()){JOptionPane.showMessageDialog(this,\该课号以存在,无法添加\ else{ stmt.executeUpdate(sql); JOptionPane.showMessageDialog(this,\添加成功\ } rs1.close(); stmt.close(); } catch(SQLException e){ System.out.print(\ } } }
//连接数据库方法
public static Connection CONN(){ String driverName = \ //加载JDBC驱动 String dbURL = \ //连接服
相关推荐: