开发者

Sign in button has no visible effect in a Java application

I have two applications, one is a server and the other is a client. At first, I run my server application. Then I will run the client application. When running the client application, a window will be shown to prompt for a username and password and if they were correct, another window will be shown. When I click on the “Sign In” button, nothing happens. What's wrong?

Main class in Server application:

 public static void main(String[] args) {
    System.out.println("Server is starting...");

    ServerSocket server = null;
    try {
        server = new ServerSocket(5000);
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

    System.out.println("Server is listening...");
    while (true) {
        try {
            Socket socket = server.accept();
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println("Client Connected...");

    }
}

Client class which has a socket in it:

private static InformationClass info = new InformationClass();
private static Socket c;
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

/**
 * @param args the command line arguments
 */
public static void runAClient() {
    try {
        c = new Socket("localhost", 5000);
    } catch (UnknownHostException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}
public static void clienT(){
    try {
        BufferedReader read = new BufferedReader(new InputStreamReader(c.getInputStream()));
        BufferedWriter write = new BufferedWriter(new OutputStreamWriter(c.getOutputStream()));
        while (true) {
            String string = reader.readLine();
            write.write(string, 0, string.length());
            write.newLine();

            write.flush();
            System.out.println(read.readLine());
        }

    } catch (Exception e) {
        System.err.println(e);
    }
}

public static boolean connected() {
    boolean bool = false;
    if (c.isConnected()) {
        info.setSituation("Connected");
        bool = true;
    } else {
        info.setSituation("disconnected");
        bool = false;
    }
    return bool;
}

The main window in the client application, which I start after when I run the server application. A part of that is for the “Sign In” button.

private void submit() {
    String id = idField.getText();
    char[] pass1 = passField.getPassword();
    String pass = new String(pass1);
    if (id.equals("") || pass.equals("")) {
        ErrorFrame frame = new ErrorFrame();
        frame.setVisi开发者_JS百科ble(true);
    } else {
        boolean b = Manager.Test(id, pass);
        if (b == true) {
            Main.runAClient();
            boolean boOl = Main.connected();
            if(boOl==true){
                this.setVisible(false);
                ListFrame fRAme = new ListFrame(client);
                fRAme.setVisible(true);
            }
            else{
                JOptionPane.showConfirmDialog(this, "You couldn't connect successfully,please try again!","sign_In Problem",JOptionPane.ERROR_MESSAGE);
                return;
            }
        } else {
            JOptionPane.showConfirmDialog(this, "You have entered wrong datas,try it again");
            return;
        }
    }
}


Have you tried stepping through your code using a debugger to work out precisely which line of code is not working correctly? Simply stating that "nothing happens" when you click on the sign-in button doesn't give us much to go on.


Are you sure your submit() method is called when you click 'Sign In' button? Another thing, Main.RunAClient() never returns constantly asking user to enter a line in system console.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜