Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
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  
  JApplet:  JFrames errors when returned to App  (Read 722 times)
0 Members and 1 Guest are viewing this topic.
Devyn
Guest
« Posted 2004-04-13 23:35:46 »

Hi,

Please excuse if this post should not appear under this topic.  I'm doing some drawing on a panel in a JFrame that's created from an applet.  When a button is pressed on the applet a Window pops up and there are various components and drawings on that panel.  

Everything works great when the page is first loaded.  When I leave the page to go to say www.google.com then click the back button to return to the page, the JFrame no longer displays the components, draw anything or recognize any events sent to Swing components on this JFrame.  

What is being done when I leave my page in IE to go to a different one then click back?  What should I do or check to make sure my applet works correctly when I leave then return to the page?

Devyn
Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #1 - Posted 2004-04-14 02:35:18 »

JFrame and JApplet are both top level containers, and heavyweights.   In Swing you are not supposed to mix heavyweights with heavyweights.  I've experienced erratic behavior when trying to mix the two as well.  I even went so far to use a JPanel to re-implement an applet to use in a JFrame.   Worked great  Wink

Maybe you should reconsider your design; why does your JApplet need a JFrame? JApplet has menubars etc so what is the advantage of adding using a JFrame? JApplet should only contain other lightweight components.
Offline javawillie

Junior Member




Hola, Paco.


« Reply #2 - Posted 2004-04-14 18:23:17 »

Mixing JApplets and JFrames does not cause a problem in Swing--at least I have never seen that or heard of that.  (I could be wrong, but if I am, I'd be very interested and grateful to be enlighted with a relevant link or explanation.)  The problems arise when one tries to add a heavyweight object to a lightweight object.  Besides, JFrames are not added to the applet's container tree anyway.

Also it is often useful to have JFrames in applets.  For example you might want to allow the user to resize the UI.  We do this pretty often where I work.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Devyn
Guest
« Reply #3 - Posted 2004-04-14 18:53:35 »

Hi all,

Well I got it to display the JFrames correctly now when the 'Back' button is pressed.  All the panels are now repainted fine when I return to the page, but the JTextFields (Except for the first one clicked) no longer accept input or focus requests.  All other components like radio buttons do.

When I click on the first JTextField it get's the focus and the cursor, but the following JTextField no longer get's any focus when clicked.

I noticed also that when I reinstantiate a single major JPanel I have on my applet, everything works fine and I can press back as many times as I like and there are no problems.  I might stay with that but I would like to maintain as much of the applet current state as I can when the user returns to it.

I'm starting to think that it's probaby an event queue problem, or something to do with listeners added to components.  Since I have no idea what IE does to an applet when a user leaves a page, it's hard to tell.

Devyn

BTW, I'm not adding JFrames to the JApplet.  I'm creating new windows using JFrames from within panels that have been added to the JApplet.
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.

xsi3rr4x (52 views)
2014-04-15 18:08:23

BurntPizza (49 views)
2014-04-15 03:46:01

UprightPath (64 views)
2014-04-14 17:39:50

UprightPath (46 views)
2014-04-14 17:35:47

Porlus (63 views)
2014-04-14 15:48:38

tom_mai78101 (88 views)
2014-04-10 04:04:31

BurntPizza (147 views)
2014-04-08 23:06:04

tom_mai78101 (244 views)
2014-04-05 13:34:39

trollwarrior1 (203 views)
2014-04-04 12:06:45

CJLetsGame (210 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!