Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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 1700 times)
0 Members and 1 Guest are viewing this topic.
Offline Karmington

Senior Duke


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 Duke


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

<code>
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;
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
      
   }

   /**run  */
   public void run(){
      try {
         
         
         device.setFullScreenWindow(frame);
         DisplayMode displayMode = device.getDisplayMode();
           
         frame.createBufferStrategy(2);
            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)
            {
               device.setFullScreenWindow(null);
               frame.setVisible(false);
               System.exit(0);
            }
            
            public void windowActivated(WindowEvent e)
            {
               Console.print("XXXXXXXXXXXXX activated");
               device.setFullScreenWindow(frame);
            }
            public void windowDeactivated(WindowEvent e)
            {
               Console.print("deactivated");
            }
         });
           
          Graphics g = strategy.getDrawGraphics();
   
          frame.add(panel);
          panel.setBufferStrategy(strategy);
                        panel.setDisplayMode(displayMode);
          panel.init();
          
         while(running) {
         
            //Console.print("running");
            
            g = strategy.getDrawGraphics();
            
            panel.update(g);
            
            strategy.show();

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

         device.setFullScreenWindow(null);
         frame.setVisible(false);
         System.exit(0);
      }
   }

   
    public static void main(String[] argv) {
        Console.print("main()");
        FullScreenSlicks t = new FullScreenSlicks();
        Thread th = new Thread(t);
        th.start();
       
    }
   
</code>

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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (43 views)
2014-10-17 03:59:02

Norakomi (33 views)
2014-10-16 15:22:06

Norakomi (26 views)
2014-10-16 15:20:20

lcass (30 views)
2014-10-15 16:18:58

TehJavaDev (60 views)
2014-10-14 00:39:48

TehJavaDev (60 views)
2014-10-14 00:35:47

TehJavaDev (50 views)
2014-10-14 00:32:37

BurntPizza (66 views)
2014-10-11 23:24:42

BurntPizza (38 views)
2014-10-11 23:10:45

BurntPizza (80 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!