OK, I took these two lines out of the program:JPanel drawAndDealPanel = new JPanel(); this.add(drawAndDealPanel); So now I got rid of the little gray squares, but I can not figure out why my cards change every time I resize the frame. Thanks in advance, E

ps - now I see the forum software has messed up the [i] parts... so never mind the above...

paintComponent is called to render its JComponent. It should contain only code that pertains to painting.

Each time the component is resized it calls paintComponent to repaint itself in the newly–resized container. So all the code in paintComponent is executed. Your call to shuffle is the cause of your cards changing after resizing. shuffle should only be called in an event handler.

setBackground is a Component method and belongs in the class constructor (which I see you already have).

Although SolitaireProject extends JApplet you have written it as an application (with a constructor). To write it as an applet you would use init and load the applet into your JFrame in main.

Now you can also run it in appletviewer with this comment at the top of the SolitaireProject file

Thanks so much. I fixed my problems by taking these lines out of the code: //(In public void paintComponent) shuffle();JPanel drawAndDealPanel = new JPanel(); . . . this.add(drawAndDealPanel); Thanks for the help!!!

jay smith
Greenhorn

Joined: May 03, 2004
Posts: 23

posted May 04, 2004 11:41:00

0

If I want to separate this into 3 files (main, gui, and logic), what would be the best way? I would leave paintComponent in the GUI, but I want to move the dealing of the cards to the logic. But, I am using paintIcon to draw the cards. Any suggestions? Thanks in advance, Jay