我调了三天 也没找到 郁闷源代码
package connDB;
import  java.sql.*;
public class DatabaseConn
{
private Statement stmt = null ;
private Connection conn = null;
    ResultSet rs = null ;
String sql ; public DatabaseConn ( )  //构造方法
{
} public void OpenConn ( ) throws Exception  //打开数据库的方法
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:stuDB");
}
catch ( Exception e )
{
System.err.println ("数据库连接:" + e.getMessage ( ) ) ; 
}
}
public ResultSet excuteQuery ( String sql )  //查询数据的方法
{
stmt = null ;
rs = null ;
try
{
stmt = conn.createStatement ( ResultSet.TYPE_SCROLL_INSENSITIVE ,
ResultSet.CONCUR_READ_ONLY ) ;
rs = stmt.executeQuery ( sql ) ;
}
catch ( SQLException e )
{
System.err.println ( "查询数据:" + e.getMessage ( ) ) ; 
}
return rs ;
} public void executeUpdate ( String sql )   //更新数据的方法
{
stmt = null ;
rs = null ;
try
{
stmt = conn.createStatement ( ResultSet.TYPE_SCROLL_INSENSITIVE ,
ResultSet.CONCUR_READ_ONLY ) ;
stmt.executeQuery ( sql ) ;
conn.commit ( ) ;
}
catch ( SQLException e )
{
System.err.println( "更新数据; " + e.getMessage ( ) );
}
} public void closeStmt ( )    //释放对象的方法
{
try
{
stmt.close ( );
}
catch ( SQLException e )
{
System.err.println ( "释放对象: " + e.getMessage ( ) );
}
} public void closeConn ( )      //释放对象的方法
{
try
{
conn.close ( );
}
catch ( SQLException e)
{
System.err.println ( "释放对象: " + e.getMessage ( ) );
}
} public static String toGBK ( String str)   //转换编码的方法
{
try
{
if ( str == null )
{
str = " ";
}
else
{
str = new String ( str.getBytes ("ISO-8859-1"),"GBK");
}
}
catch ( Exception e)
{
System.out.println ( e );
}
return str ;
}  
}

解决方案 »

  1.   

    import java.awt.* ;
    import java.awt.event.* ;
    import javax.swing.* ;
    import java.net.* ;
    import student.* ;
    public class StuMain extends JFrame implements ActionListener
    {
    //private static final long serialVersionUID = 1L ;
    //定义菜单栏名称、菜单与菜单选项
    //建立菜单栏
    JMenuBar  mainMenu = new JMenuBar ( ) ;
    //建立“系统管理”菜单组
    JMenu  menuSystem = new JMenu ( ) ;
    JMenuItem itemExit = new JMenuItem ( ) ;
    //建立“学生管理”菜单组
    JMenu menuStu = new JMenu ( ) ;
    JMenuItem itemAddS = new JMenuItem ( ) ;
    JMenuItem itemEditS = new JMenuItem ( ) ;
    JMenuItem itemDeleteS = new JMenuItem ( ) ;
    JMenuItem itemSelectS = new JMenuItem ( ) ;
    //建立"课程管理"菜单组
    JMenu menuCou = new JMenu ( ) ;
    JMenuItem itemAddC = new JMenuItem ( ) ;
    JMenuItem itemEditC = new JMenuItem ( ) ;
    JMenuItem itemDeleteC = new JMenuItem ( ) ;
    JMenuItem itemSelectC = new JMenuItem ( ) ;
    //建立"成绩管理"菜单组
    JMenu menuGra = new JMenu ( ) ;
    JMenuItem itemAddG = new JMenuItem ( ) ;
    JMenuItem itemEditG = new JMenuItem ( ) ;
    JMenuItem itemDeleteG = new JMenuItem ( ) ;
    JMenuItem itemSelectG = new JMenuItem ( ) ;



    //创建窗体模板对象
    //     public static StuInfo stuInfo = new StuInfo( ) ;
    //     public static CourseInfo stuInfo = new CourseInfo( ) ;
    //     public static GradeInfo stuInfo = new GradeInfo( ) ;

       //Image icon ;  //主窗口标题栏图标
    public StuMain ( )  //构造方法
    {
    //程序初始化
    enableEvents ( AWTEvent.WINDOW_EVENT_MASK);   
    this.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ); //添加窗口的关闭事件处理

    this.pack ( ) ;   
    this.setSize ( 800 , 500 ) ;   //设置窗口大小
    this.setTitle ( "学生管理信息系统主窗口" ) ;//设置标题
    //icon = getImage ( "icon.gif" ) ;
    try
    {
    Init ( ) ;
    }
    catch ( Exception e)
    {
    e.printStackTrace ( ) ;
    }
    } private void Init ( ) throws Exception
    {
    //程序初始化
    Container  contentPane = this.getContentPane ( ) ;
    contentPane.setLayout ( new BorderLayout ( ) ) ;
    //添加菜单组
    menuSystem.setText ( "系统管理 " );
    menuSystem.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    menuStu.setText ( "学生管理 " );
    menuSystem.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    menuCou.setText ( "课程管理 " );
    menuSystem.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    menuGra.setText ( "成绩管理 " );
    menuSystem.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    //生成“系统管理”菜单组的选项
    itemExit.setText ( " 退出 " ) ;
    itemExit.setFont ( new Font ( " Dialog " , 0 ,12 ) ) ;
    //生成“学生管理”菜单组的选项
    itemAddS.setText ( " 增加 " );
    itemAddS.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    itemEditS.setText ( " 修改 " );
    itemEditS.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    itemDeleteS.setText ( " 删除 " );
    itemDeleteS.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    itemSelectS.setText ( " 查询 " );
    itemSelectS.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    //生成“课程管理”菜单组的选项
    itemAddC.setText ( " 增加 " );
    itemAddC.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    itemEditC.setText ( " 修改 " );
    itemEditC.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    itemDeleteC.setText ( " 删除 " );
    itemDeleteC.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    itemSelectC.setText ( " 查询 " );
    itemSelectC.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    //生成“成绩管理”菜单组的选项
    itemAddG.setText ( " 增加 " );
    itemAddG.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    itemEditG.setText ( " 修改 " );
    itemEditG.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    itemDeleteG.setText ( " 删除 " );
    itemDeleteG.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    itemSelectG.setText ( " 查询 " );
    itemSelectG.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    //添加“系统管理”菜单组
    menuSystem.add ( itemExit ) ;
    //添加“学生管理”菜单组
    menuStu.add ( itemAddS ) ;
    menuStu.add ( itemEditS ) ;
    menuStu.add ( itemDeleteS ) ;
    menuStu.addSeparator ( ) ;
    menuStu.add ( itemSelectS ) ;
    //添加“课程管理”菜单组
    menuCou.add ( itemAddC ) ;
    menuCou.add ( itemEditC ) ;
    menuCou.add ( itemDeleteC ) ;
    menuCou.addSeparator ( ) ;
    menuCou.add ( itemSelectC ) ;
    //添加“成绩管理”菜单组
    menuGra.add ( itemAddG ) ;
    menuGra.add ( itemEditG ) ;
    menuGra.add ( itemDeleteG ) ;
    menuGra.addSeparator ( ) ;
    menuGra.add ( itemSelectG ) ;
            //组合栏菜单
    mainMenu.add ( menuSystem ) ;
    mainMenu.add ( menuStu ) ;
    mainMenu.add ( menuCou ) ;
    mainMenu.add ( menuGra ) ;
    this.setJMenuBar ( mainMenu ) ;
    //添加事件侦听
    itemExit.addActionListener ( this ) ;
    itemAddS.addActionListener ( this ) ;
    itemEditS.addActionListener ( this ) ;
    itemDeleteS.addActionListener ( this ) ;
    itemSelectS.addActionListener ( this ) ;
    itemAddC.addActionListener ( this ) ;
    itemEditC.addActionListener ( this ) ;
    itemDeleteC.addActionListener ( this ) ;
    itemSelectC.addActionListener ( this ) ;
    itemAddG.addActionListener ( this ) ;
    itemEditG.addActionListener ( this ) ;
    itemDeleteG.addActionListener ( this ) ;
    itemSelectG.addActionListener ( this ) ; setVisible ( true ) ;
    this.addWindowListener ( new WindowAdapter ( )   {  //关闭程序时的操作
    public void windowClosing ( WindowEvent e ) { System.exit ( 0 ) ;}
    } ) ;
    } public void actionPerformed ( ActionEvent e ) 
    {
    Object obj = e.getSource ( ) ;
    if ( obj == itemExit)          //退出
    {
    System.exit ( 0 ) ;        
    }
    else if (obj == itemAddS)
    {
    // //学生信息添加
    // AddStuInfo asi = new AddStuInfo ( ) ;   //创建信息对象 ( 窗口 )
    // asi.downInit ( ) ;         
    // asi.pack ( ) ;
    // asi.setVisible ( true ) ;
    }
    else if ( obj == itemEditS)
    {
    //学生信息修改
    // EditStuInfo esi = new EditsStuInfo ( ) ;   //创建信息对象 ( 窗口 )
    // esi.downInit ( ) ;         
    // esi.pack ( );
    // esi.setVisible ( true ) ;
    }
    else if ( obj == itemDeleteS)
    {
    //学生信息删除
    // DelStuInfo dsi = new DelStuInfo ( ) ;     //创建信息对象 ( 窗口 )
    // dsi.downInit ( ) ;
    // dsi.pack ( );
    // dsi.setVisible ( true ) ;
    }
    else if (obj == itemSelectS)
    {
    //学生信息查询
    StuSearchSnum ssSnum = new StuSearchSnum ( ) ;    //创建信息对象 ( 窗口 )
    ssSnum.pack ( );
    ssSnum.setVisible ( true ) ;
    }
    }
    // Image getImage( String filename)
    // {
    // URLClassLoader urlLoader = (URLClassLoader) this.getClass().getClassLoader();
    // URL url = null ;
    // Image image = null ;
    // image = Toolkit.getDefaultToolkit().getImage(url);
    // MediaTracker mediatracker = new MediaTracker ( this);
    // try 
    // {
    // mediatracker.addImage(image, 0);
    // mediatracker.waitForID(0);
    // }
    // catch (InterruptedException  _ex)
    // {
    // image = null ;
    // }
    // if (mediatracker.isErrorID(0))
    // {
    //    image = null ;
    // }
    //     return image ;
    // }


    public static void main ( String[] args ) 
    {
    try 
    {
    UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName());

    }
    catch (Exception e)
    {
    e.printStackTrace();

    }
    new StuMain ();
    }
    }
      

  2.   

    package student ;import java.awt.* ;
    import java.sql.* ;
    import javax.swing.* ;
    import javax.swing.table.* ;
    import java.util.* ;
    import java.awt.event.* ;
    import java.net.* ;public class ResultStudent extends JFrame
    {
    JLabel jLabel1 = new JLabel ( ) ;
    JButton jBExit = new JButton ( ) ;
    JScrollPane  jScrollPanel ;
    JTable jTabStuInfo ;
    String sNum ;
    String[]  列名 = { " 学号 " , " 姓名 " , " 性别 " , " 民族 " , " 籍贯 " , "系 " , " 学院 ", " 年级 "  , " 出生日期 " } ;
    String[][]  列值 ;     // 二维数组变量
    String sColValue ;
    String sColName ;
    String sFromValue ;
    String sToValue ;
    // public ResultStudent ( String colname , String colvalue ) 
    // {
    // this.sColValue = colvalue ;
    // this.sColName = colname ;
    // this.setTitle ( " 学生信息查询结果 " ) ;
    // //设置运行位置,使对话框居中
    // Dimension screenSize = Toolkit.getDefaultToolkit ( ) .getScreenSize ( ) ;
    // this.setLocation ( ( int )  ( screenSize.width = 400 ) / 2, ( int ) ( screenSize.height  - 300 )  / 2 + 45 ) ;
    // StuBean rStu = new StuBean ( ) ;
    // try
    // {
    // 列值 = rStu.stuAllSearch( sColName ,sColValue ) ;
    // if ( 列值 == null )
    // {
    // JOptionPane.showMessageDialog ( null , "没有符合条件的记录" ) ;
    // this.dispose ( ) ;
    // }
    // else 
    // {
    // jTabStuInfo = new JTable ( 列值 , 列名 ) ;  //创建表格对象
    // jScrollPanel = new JScrollPane ( jTabStuInfo ) ;
    // this.getContentPane ( ).add ( jScrollPanel , BorderLayout.CENTER ) ;
    // this.pack ( );
    // this .setVisible ( true ) ;
    // }
    // }
    // catch ( Exception e)
    // {
    // e.printStackTrace ( ) ;
    // }
    // } public ResultStudent ( String colname , String fromvalue , String tovalue )
    {
    this.sColName = colname ;
    this.sFromValue = fromvalue;
    this.sToValue = tovalue ;
    this.setTitle ( "学生信息查询结果" ) ;
    //设置运行位置,使对话框居中
    Dimension screenSize = Toolkit.getDefaultToolkit ( ) .getScreenSize ( ) ;
    this.setLocation ( ( int )  ( screenSize.width = 400 ) / 2, ( int ) ( screenSize.height  - 300 )  / 2 + 45 ) ;
    StuBean  rStu = new StuBean ( ) ;
    try
    {
    列值 = rStu.stuAllSearch ( sColName , sFromValue , sToValue) ;
    if ( 列值 == null )
    {
    JOptionPane.showMessageDialog ( null , "没有符合条件的记录" ) ;
    this.dispose ( ) ;
    }
    else 
    {
    jTabStuInfo = new JTable ( 列值 , 列名 ) ;  //创建表格对象
    jScrollPanel = new JScrollPane ( jTabStuInfo ) ;
    this.getContentPane ( ).add ( jScrollPanel , BorderLayout.CENTER ) ;
    this.pack ( );
    this .setVisible ( true ) ;
    }
    }
    catch ( Exception e)
    {
    e.printStackTrace ( ) ;
    }
    }
    }
      

  3.   

    package student;
    import  java.util.*;
    import  java.sql.*;
    import javax.swing.*;
    import connDB.DatabaseConn;public class StuBean
    {
    String sql ;
    ResultSet  rs = null ;
    String sNum;
    String sName;
    String sSex;
    String sBirth;
    String sHome;
    String sEthnic;
    String sYear;
    String sMajor;
    String sCollege;
    String colName;          //列名
    String colValue;          //列值
    String colValue2;        //列值
    int stuId;                    //学生的新学号 //添加学生的信息
    public void stuAdd ( String name, String sex , String birth, String home, String ethnic, String year, String major, String college )
    {
    DatabaseConn DB = new DatabaseConn ( ) ;
    this.sName = name ;
    this.sSex = sex ;
    this.sBirth = birth ;
    this.sHome = home ;
    this.sEthnic = ethnic ;
    this.sYear = year ;
    this.sMajor = major ;
    this.sCollege = college ;
    if ( sName == null || sName.equals ( " ") )
    {
    JOptionPane.showMessageDialog ( null , " 请输入学生姓名", "错误 ", JOptionPane.ERROR_MESSAGE ) ;
    return ;
    }
    else
    {
    sql = " insert into student ( sname, ssex, sbirth, shome, sethnic, syear, smajor, scollege) values ( ' " +sName+" ',' "+sSex+" ',' " + sBirth + " ', ' " + sHome + " ', ' " + sEthnic+ " ', ' " + sYear + " ', ' " + sMajor + " ',' " + sCollege + " ') " ; 
    try
    {
    DB.OpenConn ( ) ;
    DB.executeUpdate ( sql ) ;
    JOptionPane.showMessageDialog ( null , "成功添加一条新纪录! " ) ;
    }
    catch ( Exception e)
    {
    System.out.println ( e ) ;
    JOptionPane.showMessageDialog ( null , "保存失败 " , "错误 ", JOptionPane.ERROR_MESSAGE ) ;
    }
    finally
    {
    DB.closeStmt ( ) ;
    DB.closeConn ( ) ;
    }    
    }
    } //修改学生信息
    public void stuModify ( String num , String name, String sex , String birth, String home, String ethnic, String year, String major, String college )
    {
    DatabaseConn DB = new DatabaseConn ( ) ;
    this.sNum = num ;
    this.sName = name ;
    this.sSex = sex ;
    this.sBirth = birth ;
    this.sHome = home ;
    this.sEthnic = ethnic ;
    this.sYear = year ;
    this.sMajor = major ;
    this.sCollege = college ;
    if ( sName == null || sName.equals ( " ") )
    {
    JOptionPane.showMessageDialog ( null , " 请输入学生姓名", "错误 ", JOptionPane.ERROR_MESSAGE ) ;
    return ;
    }
    else
    {
    sql = " update student set sname = ' " + sName + " ',ssex = ' " + sSex + " ', sbirth = ' " + sBirth + "', shome = ' " + sHome + " ',sethnic = ' " +  sEthnic + " ', syear = ' " + sYear + " ', smajor= ' " + sMajor +" ',scollege = ' " + sCollege + " ' where snum  =" + Integer.parseInt(sNum)  + "" ;
    try
    {
    DB.OpenConn ( ) ;
    DB.executeUpdate ( sql ) ;
    JOptionPane.showMessageDialog ( null , "成功修改一条新纪录! " ) ;
    }
    catch ( Exception e)
    {
    System.out.println ( e ) ;
    JOptionPane.showMessageDialog ( null , "更新失败 " , "错误 ", JOptionPane.ERROR_MESSAGE ) ;
    }
    finally
    {
    DB.closeStmt ( ) ;
    DB.closeConn ( ) ;
    }    
    }
    } //删除学生信息
    public void stuDel ( String num ) 
    {
    DatabaseConn DB = new DatabaseConn ( ) ;
    this.sNum = num ;
    sql = " delete from student where snum = " + Integer.parseInt (sNum)+""; try
    {
    DB.OpenConn ( ) ;
    DB.executeUpdate ( sql ) ;
    JOptionPane.showMessageDialog ( null , "成功删除一条新纪录! " ) ;
    }
    catch ( Exception e)
    {
    System.out.println ( e ) ;
    JOptionPane.showMessageDialog ( null , "删除失败 " , "错误 ", JOptionPane.ERROR_MESSAGE ) ;
    }
    finally
    {
    DB.closeStmt ( ) ;
    DB.closeConn ( ) ;
    }    
    }
    //根据指定学号查询学生信息
    // public String[] stuSearch ( String sname ,String num )
    // {
    // DatabaseConn DB = new DatabaseConn ( ) ;
    // this.sNum = num ;
    // this.sName = sname;
    // String[] s = new String[8] ;
    // sql = " select * from strdent where "+this.sName+" = " + Integer.parseInt (sNum)+"";
    // try
    // {
    // DB.OpenConn ( ) ;
    // rs = DB.excuteQuery(sql);
    // if ( rs. next ( ) )
    // {
    // s[0] = rs.getString ( "sname") ;
    // s[1] = rs.getString ( "ssex " ) ;
    // s[2] = rs.getString ( "sethnic " ) ;
    // s[3] = rs.getString ( "shome " ) ;
    // s[4] = rs.getString ( "syear " ) ;
    // s[5] = rs.getString ( "smajor " ) ;
    // s[6] = rs.getString ( "scollege " ) ;
    // s[7] = rs.getString ( "sbirth " ) ;
    // }
    // else
    // {
    // s = null ;
    // }
    // }
    // catch ( Exception e)
    // {
    // }
    // finally
    // {
    // DB.closeStmt ( ) ;
    // DB.closeConn ( ) ;
    // }
    // return s ;
    // } //根据指定的学号范围查询学生信息
    public String[][] stuAllSearch( String xh, String h1, String h2)
    {
    this.colName = xh ;
    this.colValue = h1 ;
    this.colValue2 = h2 ;
    DatabaseConn DB = new DatabaseConn( );
    String[][] sn = null ;
    int row = 0 ;
    int i = 0 ;
    sql = " select * from student where "+ colName +" between " + colValue + " and " + colValue2 + " " ;
    try
    {
    DB.OpenConn();
    rs = DB.excuteQuery ( sql ) ;
    if ( rs.last ( ))
    {
    row = rs.getRow ( ) ;
    }
    if ( row == 0 )
    {
    sn = null ;
    }
    else
    {
    sn = new String [ row ] [ 9 ] ;
    rs.first ( ) ;
    rs.previous ( ) ;
    while ( rs.next ( ) )
    {
    sn [ i ] [ 0 ] = rs.getString ( "snum" ) ;
    sn [ i ] [ 1 ] = rs.getString ( "sname" ) ;
    sn [ i ] [ 2 ] = rs.getString ( "ssex" ) ;
    sn [ i ] [ 3 ] = rs.getString ( "sethnic" ) ;
    sn [ i ] [ 4 ] = rs.getString ( "shome" ) ;
    sn [ i ] [ 5 ] = rs.getString ( "syear" ) ;
    sn [ i ] [ 6 ] = rs.getString ( "smajor" ) ;
    sn [ i ] [ 7 ] = rs.getString ( "scollege" ) ;
    sn [ i ] [ 8 ] = rs.getString ( "sbirth" ) ;
    i++ ;
    }
    }
    }
    catch ( Exception e)
    {
    }
    finally
    {
    DB.closeStmt ( ) ;
    DB.closeConn ( ) ;
    }
    return sn;
    } //获得新学号
    public int getStuId ( )
    {
    DatabaseConn DB = new DatabaseConn ( ) ;
    sql = " select max(snum) from  student " ;
    try
    {
    DB.OpenConn ( ) ;
    rs = DB.excuteQuery ( sql );
    if ( rs.next ( ) )
    {
    stuId = rs.getInt ( 1 ) + 1 ;
    }
    else
    {
    stuId = 1 ;
    }
    }
    catch ( Exception e)
    {
    }
    finally
    {
    DB.closeStmt ( ) ;
    DB.closeConn ( ) ;
    }
    return stuId;
    } //获得student表中的所有学号sNum
    public String[] getAllId ( )
    {
    String[] s = null ;
    int row = 0 ;
    int i = 0 ;
    DatabaseConn DB = new DatabaseConn ( ) ;
    sql =  " select snum from student " ;
    try
    {
    DB.OpenConn ( ) ;
    rs = DB.excuteQuery ( sql ) ;
    if ( rs.last ( ) )
    {
    row = rs.getRow ( ) ;
    }
    if ( row == 0)
    {
    s = null ;
    }
    else
    {
    s = new String [ row ] ;
    rs.first ( ) ;
    rs.previous ( ) ;
    while ( rs.next ( ))
    {
    s[ i ] = rs.getString (1);
    i ++ ;
    }
    }
    }
    catch ( Exception e)
    {
    System.out.println ( e ) ;
    }
    finally 
    {
    DB.closeStmt ( ) ;
    DB.closeConn ( ) ;
    }
    return s;
    }
    }
      

  4.   

    package student ;import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;public class StuSearchSnum extends JFrame implements  ActionListener
    {
    Container c ;
    JLabel jLabel1 = new JLabel ( ) ;
    // JLabel jLabel2 = new JLabel ( ) ;
    JTextField sForm = new JTextField ( 4 ) ;
    // JTextField sTo = new JTextField ( 4 );
    JButton xc = new JButton ( ) ; public StuSearchSnum ( )
    {
    this.setTitle ( "按学号查询" ) ;  //设置标题
    this.setResizable ( false ) ;
    try
    {
    Init ( ) ;
    }
    catch ( Exception e)
    {
    e.printStackTrace ( ) ;
    }
    //设置运行位置,使对话框居中
    Dimension screenSize = Toolkit.getDefaultToolkit ( ) .getScreenSize ( ) ;
    this.setLocation ( ( int )  ( screenSize.width = 400 ) / 2, ( int ) ( screenSize.height  - 300 )  / 2 + 45 ) ;
         }  private void Init ( ) throws Exception 
     {
     this.setSize ( 300 ,150 ) ;
     c = this.getContentPane ( ) ;
     c.setLayout ( new FlowLayout ( ) ) ;
     jLabel1.setText ( " 请输入学号: " );
     jLabel1.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
     c.add ( jLabel1 ) ;
     sForm.setText ( null );
     sForm.setFont ( new Font ( " Dialog " , 0 ,12 ) ) ;
     c.add ( sForm ) ;
    //  jLabel2.setText ( " 到 " ) ;
    //  jLabel2.setFont ( new Font ( " Dialog " , 0 , 12 ) ) ;
    //  c.add ( jLabel2 ) ;
    //  sTo.setText ( null ) ;
    //  sTo.setFont ( new Font ( " Dialog " , 0 ,12 ) ) ;
    //  c.add ( sTo ) ;
     xc.setText ( " 确定 " ) ;
     xc.setFont ( new Font ( "Dialog " , 0 , 12 ) ) ;
     c.add ( xc ) ;
     xc.addActionListener ( this ) ;
     }
     public void actionPerformed ( ActionEvent e ) 
    {
     Object obj = e.getSource ( ) ;
     if ( obj == xc )
     {
     //查询
     ResultStudent rS = new ResultStudent ( " snum " , sForm.getText());
     this.dispose() ;
     }
    }
    }
      

  5.   

    http://download.csdn.net/source/3113415  去我空间下也可以 谢谢