简体   繁体   English

使用另一个 JFrame 访问 JFrame

[英]Accessing a JFrame using an another JFrame

I have 2 jframes,frame1 and frame2.我有 2 个 jframe,frame1 和 frame2。 I tried to inconfied frame1 using a jbutton on frame1.我试图在 frame1 上使用 jbutton 对 frame1 进行置信。 I coded jbutton like this.我像这样编写jbutton。

this.setState(JFrame.iconfied);

and it was working.它正在工作。

Then I wanted to inconfied frame2 using the same jbutton (the button which was on frame1) I coded jbutton like this.然后我想使用相同的 jbutton(在 frame1 上的按钮)对 frame2 进行 inconfied,我像这样编写了 jbutton。

frame2 frame = new frame2();
frame.setState(JFrame.iconfied);

But it was not working.但它不起作用。 "frame2" was the class name of frame2 and it was a public class, but the jbutton didn't do anything. “frame2”是 frame2 的 class 名称,它是公共 class,但 jbutton 没有做任何事情。 If someone could help me I would appreciate that a lot.如果有人可以帮助我,我将不胜感激。 Thanks...谢谢...

Finally I realized what had happened with my code.最后我意识到我的代码发生了什么。 I created an object named frame for frame2 class.我为 frame2 class 创建了一个名为 object 的框架。 Unfortunately I have created it inside of the method of jbutton which is called as jbuttonActionPerformed in Netbeans.不幸的是,我在 jbutton 的方法中创建了它,该方法在 Netbeans 中称为 jbuttonActionPerformed。 So the object was executed at each time when I clicked the button.因此,每次单击按钮时都会执行 object。 But the Object should be executed only one time.但是 Object 应该只执行一次。 I override this simple rule and encountered that problem.我覆盖了这个简单的规则并遇到了这个问题。 After cut and pasted the object line outside of the method (but inside of the class) the problem was automatically fixed.在方法外部(但在类内部)剪切并粘贴 object 行后,问题自动修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM