0

enter image description here

enter image description here

enter image description here

Okey I have a class that prints the board and another class that prints the Chess

how do I use the LayeredPane to merge them together like the example picture above? I been trying all day and nothing seems to work at all. I am using JFrame to print the picture.

kleopatra
  • 51,061
  • 28
  • 99
  • 211
ricedragon
  • 173
  • 5
  • 14
  • possible duplicate of [Java Classes , interface and Gui](http://stackoverflow.com/questions/8018333/java-classes-interface-and-gui) – trashgod Nov 05 '11 at 17:35

2 Answers2

1

You should print the chess and the board in the same paintComponent() method. So print them in the same class. You could use something like:

public void paintComponent(Graphics g) {
    printBoard(g);
    printChess(g);
}
Jonas
  • 121,568
  • 97
  • 310
  • 388
  • as a requirement i have to do them in sperate classes or I would , it makes it a lot easer – ricedragon Nov 05 '11 at 08:47
  • @ricedragon: it makes it harder. – Jonas Nov 05 '11 at 08:50
  • thats why i am asking , I have no freaking clue at all , because if i add the two object in the Jfame the ChessPiece will overwrite the Board – ricedragon Nov 05 '11 at 08:59
  • same z-index? or opaque set to true? See http://download.oracle.com/javase/tutorial/uiswing/components/layeredpane.html for more information – Tedil Nov 05 '11 at 09:47
1

Your question doesn't tell us much about the structure of your program or the specific problem that you're having. I assume that you've gone through the JLayeredPane tutorial which should explain to you pretty much the workings of a JLayeredPane, and that you understand it fully, otherwise I assume that you'd ask for clarification for your points of confusion in your question above.

I've outlined one way that I've approached a similar project in this answer: does-adding-a-jlabel-to-a-jpanel-hide-the-jpanel. Please check it out and again review the Swing tutorial and ask if anything doesn't make sense.

Community
  • 1
  • 1
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373