这段程序不知哪错了 都愁死我了 请高手指点
import *;import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import *;
class Client implements Serializable
{
private String username;
private String password;
public void setUsername(String username)
{
this.username=username;
}
public String getUsername()
{
return this.username;
}
public void setPassword(String password)
{
this.password=password;
}
public String getPassword()
{
return this.password;
}
}
class GUIClient
{
static JFrame frame,frame2,frame3;
Container c,c2,c3;
JLabel l1,l2,l3,l4;
static JTextField t1,t2;
JButton b1;
GUIClient()
{
frame=new JFrame();
c=frame.getContentPane();
c.setLayout(null);
l1=new JLabel("用户名:");
l1.setBounds(50,100,50,30);
c.add(l1);
t1=new JTextField();
t1.setBounds(100,100,100,30);
c.add(t1);
l2=new JLabel("密 码:");
l2.setBounds(50,150,50,30);
c.add(l2);
t2=new JTextField();
t2.setBounds(100,150,100,30);
c.add(t2);
b1=new JButton("确定");
b1.setBounds(100,200,80,30);
c.add(b1);
b1.addActionListener(new ServerGUIClient());
frame.setSize(300,400);
frame.setVisible(true);
frame2=new JFrame();
c2=frame2.getContentPane();
c2.setLayout(null);
Font font=new Font("楷体_GB2312",Font.PLAIN,40);
l3=new JLabel("添加成功");
l3.setBounds(50,50,200,200);
l3.setFont(font);
c2.add(l3);
frame2.setSize(300,300);
frame2.setVisible(false);
frame3=new JFrame();
c3=frame3.getContentPane();
c3.setLayout(null);
l4=new JLabel("添加失败");
l4.setBounds(50,50,200,200);
l4.setFont(font);
c3.add(l4);
frame3.setSize(300,300);
frame3.setVisible(false);
}
class ServerGUIClient implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object obj=e.getSource();
if(obj==b1)
{
Client c=new Client();
c.setUsername(t1.getText());
c.setPassword(t2.getText());
try
{
Socket toServer;
toServer=new Socket("localhost",9192);
ObjectOutputStream streamToServer=new ObjectOutputStream(toServer.getOutputStream());
streamToServer.writeObject(c);
streamToServer.close();
}
catch(InvalidClassException e1)
{
System.out.println("InvalidClassException");
e1.printStackTrace();
}
catch(NotSerializableException e1)
{
System.out.println("NotSerializableException");
e1.printStackTrace();
}
catch(IOException e1)
{
System.out.println("IOException");
e1.printStackTrace();
}
}
}
}
public static void main(String args[])
{
new GUIClient();
}
}
这是客户端程序
import *;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import *;
import java.sql.*;
/*class Server implements Serializable
{
private String username;
private String password;
public void setUsername(String username)
{
this.username=username;
}
public String getUsername()
{
return this.username;
}
public void setPassword(String password)
{
this.password=password;
}
public String getPassword()
{
return this.password;
}
}*/
class Servers
{
ServerSocket server;
Socket fromClient;
public Servers()
{
try
{
server=new ServerSocket(9192);
System.out.println("服务器在9192端口监听");
fromClient=server.accept();
String regex="\\d{6}";
if(GUIClient.t1.getText().matches(regex)&&GUIClient.t2.getText().matches(regex))
{
GUIClient.frame2.setVisible(true);
SQLBean sqlb=new SQLBean(fromClient);
}
else
{
GUIClient.frame3.setVisible(true);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String args[])
{
new Servers();
}
}
class SQLBean
{
Client data;
ObjectInputStream streamFromClient;
public SQLBean(Socket inFromClient)
{
try
{
streamFromClient=new ObjectInputStream(inFromClient.getInputStream());
try
{
data=(Client)streamFromClient.readObject();
}
catch(InvalidClassException e)
{
System.out.println("InvalidClassException");
e.printStackTrace();
}
catch(NotSerializableException e)
{
System.out.println("NotSerializableException");
e.printStackTrace();
}
catch(IOException e)
{
System.out.println("IOException");
e.printStackTrace();
submit();
}
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
}
public void submit()
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con;
con=DriverManager.getConnection("jdbc:odbc:jq91","sa","sa");
PreparedStatement stat=con.prepareStatement("insert into message(name,password) values(?,?)");
stat.setString(1,data.getUsername());
stat.setString(2,data.getPassword());
stat.executeUpdate();
}
catch(Exception e)
{
System.out.println("添加失败");
}
}
}
这是服务器端程序