Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Applet, Application, JFrame, JPanel confusion  (Read 1846 times)
0 Members and 1 Guest are viewing this topic.
Offline Karmington

Senior Devvie

Medals: 1
Projects: 1

Co-op Freak

« Posted 2009-07-29 11:22:12 »

I'm a bit hazy as to the true meaning of JFrame and Jpanel.
I can add a JFrame to an application, and it draws nicely directly on to the frame.
But am I supposed to make a Panel that is drawn on to, and pass the Panel to the frame?

And what about when I try to make this into an applet - I can't add a JFrame to the Applet,
getting 'java.lang.IllegalArgumentException: adding a window to a container'

So I can make the Jpanel and add that, but what is the function of the JFrame then?
should I make a blank JFrame receptacle in the Application to receive the JPanel,
and put all my code in JPanel?

once more with feeling to clear up the structure:
I'm trying to separate all the real code from the Applet and Application Initialization and Running.
so at the moment:

Applet -> makes JPanel -> adds JPanel
Application -> makes JFrame -> adds JFrame
_this is BAD_ because I have cloned class, JPanel and JFrame are nearly identical ( I am testing this to figure it out as I go also )

should this be
Applet -> makes JPanel -> adds JPanel
Application -> makes JFrame -> makes -> JPanel -> addPanelToFrame -> addFrameToApplication?

Offline h3ckboy

JGO Coder

Medals: 5

« Reply #1 - Posted 2009-07-29 11:43:26 »

I always thought the JFrame was the window.

the panel can set certain content. Like an htmlpane can display websites.
Offline Karmington

Senior Devvie

Medals: 1
Projects: 1

Co-op Freak

« Reply #2 - Posted 2009-07-29 15:04:28 »

Okay, put everything in a panel and things are looking nicer...
However if user Alt+Tabs out and back everything gets really blinky...
maybe i punch in some code here, this is shooting in the dark how to handle reassembling the screen..

Oh boy this gets messy, when I make the executable jar
it loses keylisteners and mouselisteners... hmm hmm it seems
to be a bit random whether it gets Listeners in the Eclipse build also...
who steals my listeners... oivoi

public class FullScreenSlicks implements Runnable /*, FocusListener*/{

   private boolean running;
    GraphicsDevice device;
   SlicksPanel panel;
   JFrame frame;
    public FullScreenSlicks() {
       Console.print("Create FullScreenSlicks Object");
      frame = new JFrame();
      panel = new SlicksPanel();
       running = true;
      device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

   /**run  */
   public void run(){
      try {
         DisplayMode displayMode = device.getDisplayMode();
            BufferStrategy strategy = frame.getBufferStrategy();
            int w = displayMode.getWidth();
            int h = displayMode.getHeight();
            panel.setSize(w, h);
            Console.print("found screen w:"+w+", h:"+h);
            frame.addWindowListener(new WindowAdapter()
            public void windowClosing(WindowEvent e)
            public void windowActivated(WindowEvent e)
               Console.print("XXXXXXXXXXXXX activated");
            public void windowDeactivated(WindowEvent e)
          Graphics g = strategy.getDrawGraphics();
         while(running) {
            g = strategy.getDrawGraphics();

                if(panel.stop) {
                    running = false;
                if(frame.stop) {
                    running = false;
      catch(Exception e) {
      }finally{//Cleanup what ever happends.
         Console.print("do we clean up?");


    public static void main(String[] argv) {
        FullScreenSlicks t = new FullScreenSlicks();
        Thread th = new Thread(t);

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline h3ckboy

JGO Coder

Medals: 5

« Reply #3 - Posted 2009-07-29 20:19:32 »

whya re you worried about making a program that can be both applet and application. It isnt possible. Just make the best possible solution for one of them.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

bilznatch (20 views)
2015-08-04 11:03:17

SHC (39 views)
2015-08-01 03:58:20

Jesse (24 views)
2015-07-29 04:35:27

Riven (45 views)
2015-07-27 16:38:00

Riven (25 views)
2015-07-27 15:35:20

Riven (27 views)
2015-07-27 12:26:13

Riven (18 views)
2015-07-27 12:23:39

BurntPizza (41 views)
2015-07-25 00:14:37

BurntPizza (50 views)
2015-07-24 22:06:39

BurntPizza (33 views)
2015-07-24 06:06:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!