-2

I have a Java project with 2 JFrames. On one frame is a bunch of stuff drawn using the AWT Graphics library. The other frame is a settings panel using javax.swing.JPanel. The settings correctly modify the contents on the first JFrame, however when it does the modified object on the settings panel draws itself on the main JFrame (for example, if I check a checkbox in the settings, a checkbox shows on the top-left of the other JFrame). Nowhere in my code do I add the contents of the settings panel to the first JFrame. Why might this be happening?

The code is a bit long and stored into 3 different files, so I uploaded it to GitHub. You can view the full project (for Eclipse) here, or view the source files directly here. The first JFrame is in main.java and the settings JFrame is in menuObj.java.

Andy Herbert
  • 67
  • 2
  • 10
  • 1
    1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Nov 10 '16 at 11:15

1 Answers1

0

Very interesting project. Found out it is repaint(); what is causing your issue. A strange problem, never encountered it before. Though I personally dislike using repaint, instead I implement a game loop.

Check through your code in eclipse though, a lot of warnings regarding static accessing and even one unused variable. Your menuObj class extends JPanel but also has a JPanel reference variable, having two JPanels when one is doing nothing are a waste of resources, but it doesn't solve your problem. I advice you to rename your main class as well, since it shares the main method name, it works but could be a problem in the future. Naming your main class "main" or "Main" is tempting, but should be avoided.

I hope it solves your problem.

  • How would I not use `repaint()`? I tried inserting a while loop, but nothing painted. Also, I don't really want to get into Java's multithreadding, but I can probably do it if I have to – Andy Herbert Nov 10 '16 at 22:40