DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: JApplet

  1. #1
    Join Date
    Feb 2004


    Hi I have a main JPanel with 5 JPanels on this 'main' jpanel i want one panel to control the rest as it is a game and i need one manager panel. I am trying to use the paintcomponent to try and draw onto each panel but i am only getting a small box appearing, what is the problem here does anyone know?

    Is it possible to create a class for 3 jpanels i need to draw stuff on then create an instance of these classes and add to relevant jpanel to run the code and display the paintcomponents?

    Hope this all makes sense!
    Many thanks.

  2. #2
    Join Date
    Feb 2004
    hehe, it makes zero sense what so ever...

    but youre making a game, and rather than using buttons and stuff, you want to draw graphics directly on a panel?

    you would do something like this;

    public class GameView extends JPanel{
      public void paint(Graphics g){
        //draw on the graphics context provided
        g.drawText("THis is a game",100,100);
    and then you add your game panel to the display..
    how you add it/where is up to you, but theres no point putting a JPanel on the game display, than adding your GameView to that JPanel.. GameView IS A Jpanel, so just add it to the frame as you would any other panel

    Take care not to link your panels too intimately.. so if you ahve a panel that holds buttons, you dont have to combine the two.. maybe you would give reference of the gameview to the buttons panel, so that clicking a button would update the gameview.. but gameview should be a class on its own that doesnt know about buttons etc.. that way it makes it more portable, so you could take it and dump it onto your java enabled phone (perhaps) and just write a simple connector to link the phone keypad to the game functions..

    do you see, how classes should be designed to do one thing only.. and other classes be used to conenct them? theres no harm in having the buttons panel completely ignorant of the gasme view.. and clicking on a button will merely generate an event.. a registered listener for the events will pick up on it and poke the right method of gameview to make it work.. that way you could use both the gameview and the button panel in other, separate projects, without rewriting lots of code
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center