[英]How can i move one frame to another in MouseListener
我想對當前的jFrame
進行dispose()
並移至下一個jFrame(StudentProfilepage()),但是在this.dispose()
處顯示錯誤。
我該怎么辦。這里我使用MouseListner
jLabel l1
我的代碼如下
l1.setCursor(Cursor.getDefaultCursor());
l1.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
//added check for MouseEvent.BUTTON1 which is left click
if (e.isPopupTrigger() || e.getButton() == MouseEvent.BUTTON1) {
this.dispose(); //error here(i want to close my current frame and move to StudentProfile() page
new StudentProfilePage().setVisible(true);
}
}
});
this
在
this.dispose();
引用MouseAdapter
,因此會出現編譯錯誤。
您需要在JFrame
上調用處理
JFrameClassName.this.dispose();
還可以考慮使用JDialog
而不是JFrame
作為第二個窗口。 閱讀使用多個JFrame,良好/不良做法?
你應該寫
YourClassName.this.dispose();
指向您的jframe
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.