| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 913 人关注过本帖
标题:这段程序不知哪错了 都愁死我了 请高手指点
只看楼主 加入收藏
逍遥宝宝
Rank: 2
等 级:论坛游民
帖 子:14
专家分:16
注 册:2010-10-10
结帖率:100%
收藏
 问题点数:0 回复次数:7 
这段程序不知哪错了 都愁死我了 请高手指点
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("添加失败");
        }
    }
}


这是服务器端程序
搜索更多相关主题的帖子: void password private public 
2010-10-14 08:48
逍遥宝宝
Rank: 2
等 级:论坛游民
帖 子:14
专家分:16
注 册:2010-10-10
收藏
得分:0 
2010-10-14 10:12
护林农夫
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-10-12
收藏
得分:0 
高手!佩服!
2010-10-14 11:28
LSYHEFENG
Rank: 2
等 级:论坛游民
帖 子:112
专家分:71
注 册:2010-7-17
收藏
得分:0 
看完都天黑了
2010-10-16 15:28
yusan
Rank: 2
等 级:论坛游民
帖 子:17
专家分:49
注 册:2010-10-16
收藏
得分:0 
我不是学java的  不好意思帮不了你
2010-10-16 22:23
zybjava
该用户已被删除
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2010-10-17 09:10
zybjava
该用户已被删除
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2010-10-17 09:14
逍遥宝宝
Rank: 2
等 级:论坛游民
帖 子:14
专家分:16
注 册:2010-10-10
收藏
得分:0 
...
2010-10-21 21:09
快速回复:这段程序不知哪错了 都愁死我了 请高手指点
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017936 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved