登录按钮在 Java 应用程序中没有可见效果 [英] 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?
服务器应用中的主类:
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.setVisible(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.
这篇关于登录按钮在 Java 应用程序中没有可见效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!