Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JFrame inside another JFrame

I have a game of chess. I have written 3 classes. 1st if for game. (chessboard, pieces, and so on) And another one is for menu. (buttons like new, open, set time)

Both of them use JFrame.

I would like to put both classes mentioned above into the 3rd class. For example the Game window would be on the left, and the menu on the right. The third class would also show the whole app by JFrame.

How to do that?

like image 784
Ganjira Avatar asked Jun 25 '13 00:06

Ganjira


People also ask

How do you link two frames in java?

Just create another class, let us say FrameMananger, then use the singleton pattern to manage them. Then in any class, you can use FrameManager. getFrame1() to get the frame1, same as the frame2. You can add logic judgement inside, like dynamically dispose some frame or only create them when needed.

What is JComponent in java?

JComponent is an abstract class that almost all Swing components extend; it provides much of the underlying functionality common throughout the Swing component library. Just as the java. awt. Component class serves as the guiding framework for most of the AWT components, the javax.


1 Answers

You can't put one JFrame inside another. You have a couple of design choices here. You can change your JFrames to JPanels. This is probably the easiest change. On the other hand, you can look at using Internal Frames instead.

like image 183
Code-Apprentice Avatar answered Sep 27 '22 19:09

Code-Apprentice