我无法在我的PasswordFrame.java文件中调用Client_GUI.java文件中的 verify()和 connect()方法。
PasswordCheck.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
passwordCheck();
}
public void passwordCheck(){
String pass = new String(jPasswordField1.getPassword());
if (pass.equals(password))
{
Client_GUI clientGUI = new Client_GUI();
clientGUI.verify();
clientGUI.connect();
dispose();
}
else
{
System.out.println(pass);
JOptionPane.showMessageDialog(null,
"Incorrect password",
"",
JOptionPane.ERROR_MESSAGE);
}
}
Client_GUI.java
private void b_connectActionPerformed(java.awt.event.ActionEvent evt)
{
PasswordFrame passwordFrame = new PasswordFrame ();
passwordFrame.show();
}
private void tf_video_file_nameActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Client_GUI().setVisible(true);
}
});
}
public void verify() {
// SERVER IP ADDRESS INITIALISATION
// SERVER PORT INITIALISATION
if (!tf_server_port.getText().isEmpty()) {
int ServerPort = Integer.parseInt(tf_server_port.getText());
RTSP_server_port = ServerPort;
if (ServerPort <= 1024 || ServerPort > 65535) {
JOptionPane.showMessageDialog(null,
"Please enter a port number between 1024 and 65535",
"Wrong Port",
JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(null,
"Please enter a port number between 1024 and 65535",
"Wrong Port",
JOptionPane.ERROR_MESSAGE);
}
// PROTOCOL TYPE INITIALISATION
ButtonModel protocol_grp = bt_protocol_group.getSelection();
if (protocol_grp != null){
String selection = protocol_grp.getActionCommand();
if(selection.equals("tcp")){
protocolType = "tcp";
}
else if(selection.equals("udp")){
protocolType = "udp";
}
}
ButtonModel ports_grp = bt_ports_group.getSelection();
if (ports_grp != null) {
NoOfPorts = Integer.parseInt(ports_grp.getActionCommand());
}
ButtonModel vlc_grp = bt_ports_group.getSelection();
if (vlc_grp != null) {
String selection = vlc_grp.getActionCommand();
if (selection.equals("yes")) {
vlc_select = true;
}
}
ButtonModel java_vlc = bt_java_vlc.getSelection();
if (java_vlc != null) {
String selection = java_vlc.getActionCommand();
if (selection.equals("yes")) {
//vlc_player player = new vlc_player();
java_vlc_select = true;
}
}
}
System.out.println("All fields verified");
}
public void connect() {
try {
ServerIP = InetAddress.getByName(tf_server_IP.getText());
client_fnc client = new client_fnc();
client.setServerIP(ServerIP);
client.setServerIP(RTSP_server_port);
client.setServerIP(VideoFileName);
client.setframe_start_vlc(50);
client.setBuffer_Size(bufferSize);
client.setNoOfPorts(NoOfPorts);
client.setProtocolType(protocolType);
client.setFilePath(stringFilePath);
client.setVLCPath(stringVLCPath);
client.setencryption_type(encryption_type);
client.setServerIP(java_vlc_select);
client.setEncSelected(encryption_select);
client.setStartVLCatFrame(FRAME_START_VLC);
try {
Thread client_thread = new Thread(client);
client_thread.start();
client.addObserver(Client_GUI.this);
} catch (Exception ex) {
Logger.getLogger(this.getName()).log(Level.SEVERE, "WRONG IP ", ex);
}
} catch (UnknownHostException ex) {
Logger.getLogger(this.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null,
"Please enter a correct IP address.",
"IP Address wrong",
JOptionPane.ERROR_MESSAGE);
}
System.out.println("Connected to Server");
}
当我在密码字段中输入“password”并单击 jButton1 时,密码窗口将关闭而不验证Client_GUI窗口中的字段。例如,我输入20500000作为我的服务器端口。如果我在Client_GUI.java文件本身中调用方法 verify()和 connect(),则会显示错误消息“请输入1024到65535之间的端口号”“错误港口“会弹出。但是,当我从PasswordFrame文件中调用 verify()和 connect()方法时,不会弹出任何错误消息,只会显示“所有字段已验证”和“已连接到服务器”在代码的最后出现。似乎正在跳过代码的某些部分。那是为什么?
编辑:抱歉模糊不清。我正在寻找的流程基本上是这样的: 1.当按下Client_GUI框架中的 b_button 时,会弹出PasswordFrame,用户需要输入密码。 2.当按下PasswordFrame中的 jButton 时,将调用PasswordCheck方法并检查是否输入了文本,即传递 ='密码' 3.如果是,则关闭PasswordFrame并运行 verify()和 connect()方法。答案 0 :(得分:0)
感谢您试图提供帮助。我决定只在Client_GUI窗口中添加密码输入字段而不是另一个单独的框架,并在按下 b_button 时简单地调用此方法:
public void passwordCheck(){
String pass = new String(jPasswordField1.getPassword());
if (pass.equals(password))
{
verify();
connect();
}
else
{
System.out.println(pass);
JOptionPane.showMessageDialog(null,
"Incorrect password",
"",
JOptionPane.ERROR_MESSAGE);
}
}