Java JFrame更改的鼠标单击事件

Java JFrame更改的鼠标单击事件,java,swing,jframe,Java,Swing,Jframe,我想用MouseEvent将JFrame窗口更改为另一个窗口。代码如下 private void jButton1MouseClicked(java.awt.event.MouseEvent evt) { String pass; String user; user = txtUser.getText(); pass = txtPass.getText(); if(pass.equals("********") &am

我想用
MouseEvent
JFrame
窗口更改为另一个窗口。代码如下

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
String pass;
String user;
user = txtUser.getText();
pass = txtPass.getText();

if(pass.equals("********") && user.equals("**********") )
{
  ??????????
}
else{
    lblDisplay.setText("Please try again.");

如果您需要转到另一个
JFrame
如果
username
password
匹配,您可以执行以下操作

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
    String pass;
    String user;
    user = txtUser.getText();
    pass = txtPass.getText();

    if(pass.equals("********") && user.equals("**********"))
    {
        // Here you can dispose the current window
        this.dispose(); // Or you can use this.setVisible(false);

        // Then call your next window to appear
        new YourNextWindow().setVisible(true);

        // And of course you can create an object for that window,

        YourNextWindow yourNextWindow = new YourNextWindow();
        yourNextWindow.setVisible(true);
    } else {
        lblDisplay.setText("Please try again.");
    }
}
最好使用
this.dispose()
而不是使
JFrame
不可见
setVisible(false)
,因为它将在没有任何使用的情况下仍在运行

更新

如前所述,最好使用
ActionListener
而不是
MouseListener

public void jButton1ActionPerformed(ActionEvent e) {
     // Your code here
} 

您尚未添加代码。代码已更新。@ermanatikulaÇ您需要更改为另一个代码是什么意思?在同一窗口中是另一个
JFrame
还是一个
JPanel
?我的意思是另一个JFrame不使用鼠标侦听器。JButton设计用于ActionListener。阅读Swing教程中的部分,了解更多信息和工作示例。不要使用鼠标听筒。JButton设计用于ActionListener。