SWT写课程设计,窗口切换出现了问题,麻烦帮忙看一下问题
package com.DatabaseDesign;class Student{ public String studentID; public String studentName; public String studentGender; public String studentBirthday; public String studentEthnic; public String studentHometown; public String studentEnrollmentDate; public String studentMajor; public String studentDepartment; public String studentDormitory;}package com.DatabaseDesign;import org.eclipse.swt.SWT;class MainFrame //主登录界面{ protected Shell shell; private Text text; private Text text_1; /** * Launch the application. * @param args */ public void run() { try { MainFrame window = new MainFrame(); window.open(); } catch (Exception e) { e.printStackTrace(); } } /** * Open the window. */ public void open() { Display display = Display.getDefault(); createContents(); shell.open(); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } /** * Create contents of the window. * @wbp.parser.entryPoint */ protected void createContents() { shell = new Shell(SWT.MIN); shell.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); shell.setSize(450, 300); shell.setText("校园信息管理系统"); Button btnNewButton = new Button(shell, SWT.NONE); btnNewButton.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e) //监听"登录"按钮 { String userName,password; userName=text.getText(); password=text_1.getText(); if(userName.equals("student")&&password.equals("student")) { ConnectToDatabase connect=new ConnectToDatabase(); connect.run(); StudentPersonalInfoDialog dialog=new StudentPersonalInfoDialog(shell,0); dialog.run(); } } }); btnNewButton.setBounds(104, 184, 80, 27); btnNewButton.setText("登录"); Button btnNewButton_1 = new Button(shell, SWT.NONE); btnNewButton_1.setBounds(253, 184, 80, 27); btnNewButton_1.setText("退出"); text = new Text(shell, SWT.BORDER); text.setBounds(174, 76, 162, 30); text_1 = new Text(shell, SWT.BORDER); text_1.setBounds(174, 122, 162, 30); text_1.setEchoChar('*'); //密码的形式 CLabel label = new CLabel(shell, SWT.NONE); label.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL)); label.setBounds(81, 76, 67, 30); label.setText(" 用户名:"); CLabel label_1 = new CLabel(shell, SWT.NONE); label_1.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL)); label_1.setBounds(81, 122, 67, 30); label_1.setText(" 密 码:"); Tree tree = new Tree(shell, SWT.BORDER); tree.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_BACKGROUND)); tree.setBounds(0, 0, 444, 30); Tree tree_1 = new Tree(shell, SWT.BORDER); tree_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_BACKGROUND)); tree_1.setBounds(0, 232, 444, 30); Combo combo = new Combo(shell, SWT.NONE); combo.setBounds(348, 76, 59, 30); combo.add("学 生"); combo.add("教 师"); combo.add("管理员"); combo.select(0); }} package com.DatabaseDesign;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;class ConnectToDatabase //连接数据库,sqlserver2008{ String url="jdbc:sqlserver://127.0.0.1:1433;DataBaseName=SchoolManagement"; Connection con; String sql; Statement stmt; Student student=new Student(); public void run() { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch(java.lang.ClassNotFoundException e1) { System.err.print("ClassNotFoundException:"); System.err.println(e1.getMessage()); } try { con=DriverManager.getConnection(url,"student","student"); //用户名和密码都是student stmt=con.createStatement(); sql="select * from Students"; ResultSet rs=stmt.executeQuery(sql); while(rs.next()) { student.studentID=rs.getString(1); student.studentName=rs.getString(2); student.studentGender=rs.getString(3); student.studentBirthday=rs.getString(4); student.studentEthnic=rs.getString(5); student.studentHometown=rs.getString(6); student.studentEnrollmentDate=rs.getString(7); student.studentMajor=rs.getString(8); student.studentDepartment=rs.getString(9); student.studentDormitory=rs.getString(10); /*System.out.println(student.studentID+" "+student.studentName+" "+ student.studentGender+" "+student.studentBirthday+" "+student.studentEthnic+ " "+student.studentHometown+" "+student.studentEnrollmentDate+" "+student.studentMajor+ " "+student.studentDepartment+" "+student.studentDormitory);*/ } } catch(SQLException e) { System.err.println("SQLException:"+e.getMessage()); } }}package com.DatabaseDesign;import org.eclipse.swt.widgets.Dialog;class StudentPersonalInfoDialog extends Dialog //dialog界面,显示student登录后的学生信息{ protected Object result; protected Shell shell; private Text text; private Text text_1; private Text text_2; private Text text_3; private Text text_4; private Text text_5; private Text text_6; private Text text_7; private Text text_8; private Text text_9; /** * Create the dialog. * @param parent * @param style */ public StudentPersonalInfoDialog(Shell parent,int style) { super(parent,style); setText("您的信息!"); } /** * Open the dialog. * @return the result */ public Object open() { createContents(); shell.open(); shell.layout(); Display display = getParent().getDisplay(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } return result; } /** * Create contents of the dialog. */ private void createContents() { shell = new Shell(getParent(), getStyle()); shell.setSize(450, 300); shell.setText(getText()); Label label = new Label(shell, SWT.NONE); label.setBounds(10, 16, 50, 17); label.setText("学号"); text = new Text(shell, SWT.BORDER); text.setBounds(66, 13, 73, 23); ConnectToDatabase temp=new ConnectToDatabase(); text.setText(temp.student.studentID); Label label_1 = new Label(shell, SWT.NONE); label_1.setText("姓名"); label_1.setBounds(253, 16, 50, 17); Label label_2 = new Label(shell, SWT.NONE); label_2.setText("出生日期"); label_2.setBounds(10, 108, 50, 17); Label label_3 = new Label(shell, SWT.NONE); label_3.setText("学院"); label_3.setBounds(10, 151, 50, 17); Label label_4 = new Label(shell, SWT.NONE); label_4.setText("性别"); label_4.setBounds(10, 59, 50, 17); Label label_5 = new Label(shell, SWT.NONE); label_5.setText("民族"); label_5.setBounds(253, 59, 50, 17); Label label_6 = new Label(shell, SWT.NONE); label_6.setText("入学时间"); label_6.setBounds(253, 108, 50, 17); Label label_7 = new Label(shell, SWT.NONE); label_7.setText("专业"); label_7.setBounds(253, 151, 50, 17); Label label_8 = new Label(shell, SWT.NONE); label_8.setText("现居住地"); label_8.setBounds(10, 198, 50, 17); Label label_9 = new Label(shell, SWT.NONE); label_9.setText("个人籍贯"); label_9.setBounds(10, 233, 50, 17); text_1 = new Text(shell, SWT.BORDER); text_1.setBounds(324, 13, 73, 23); text_2 = new Text(shell, SWT.BORDER); text_2.setBounds(66, 56, 73, 23); text_3 = new Text(shell, SWT.BORDER); text_3.setBounds(66, 105, 73, 23); text_4 = new Text(shell, SWT.BORDER); text_4.setBounds(67, 151, 73, 23); text_5 = new Text(shell, SWT.BORDER); text_5.setBounds(67, 192, 330, 23); text_6 = new Text(shell, SWT.BORDER); text_6.setBounds(324, 56, 73, 23); text_7 = new Text(shell, SWT.BORDER); text_7.setBounds(324, 105, 73, 23); text_8 = new Text(shell, SWT.BORDER); text_8.setBounds(324, 151, 73, 23); text_9 = new Text(shell, SWT.BORDER); text_9.setBounds(66, 230, 331, 23); } public void run() { StudentPersonalInfoDialog dialog=new StudentPersonalInfoDialog(shell,0); dialog.open(); dialog.createContents(); }} package com.DatabaseDesign;public class Main{ public static void main(String[] args)throws Exception { MainFrame main=new MainFrame(); main.run(); }}