我想使用JFrame
将MouseEvent
窗口更改为另一个窗口。代码在下面。
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.");
答案 0 :(得分:-1)
如果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)
,因为它会继续运行而无需任何使用。
更新
正如camickr所说,最好使用ActionListener
而不是MouseListener
。
public void jButton1ActionPerformed(ActionEvent e) {
// Your code here
}