[英]How can i move one frame to another in MouseListener
I want to dispose()
my current jFrame
and move to the next jFrame(StudentProfilepage()).But it shows error at this.dispose()
. 我想对当前的
jFrame
进行dispose()
并移至下一个jFrame(StudentProfilepage()),但是在this.dispose()
处显示错误。
How can i do that.Here i used MouseListner
a jLabel l1
我该怎么办。这里我使用
MouseListner
jLabel l1
My code as follows 我的代码如下
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
in this
在
this.dispose();
refers to the MouseAdapter
, hence the compilation errors you are seeing. 引用
MouseAdapter
,因此会出现编译错误。
You need to invoke dispose on the JFrame
您需要在
JFrame
上调用处理
JFrameClassName.this.dispose();
Also consider using a JDialog
rather than a JFrame
as the second window. 还可以考虑使用
JDialog
而不是JFrame
作为第二个窗口。 Read The Use of Multiple JFrames, Good/Bad Practice? 阅读使用多个JFrame,良好/不良做法?
You should write 你应该写
YourClassName.this.dispose();
which points to your jframe
. 指向您的
jframe
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.