• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Applet dispaly problem

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an applet, which runs well in JBuilder - embeded in a JSP pages that runs on Tomcat. I copy and paste the URL to IE browser, it sometimes display the applet, most of times not. What can this problem is?

Thanks
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the Java console on the browser. On the IE menu, select "Tools", then select "Sun Java Console" from the drop down menu.
 
Xinyi Zhang
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess this is a thread issue. See this simple JApplet

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.SwingUtilities;

public class SimpleJApplet extends JApplet {

public void init() {
try {
GUIThread guiThread = new GUIThread();
SwingUtilities.invokeLater(guiThread);
} catch (Exception e) {
e.printStackTrace();
}
}

public void createGUI() {
getContentPane().add(new JButton("Button Two"));
}

class GUIThread implements Runnable {
public void run() {
createGUI();
}
}

}

It displays the GUI in the browser after first loaded, when I refresh the page. Sometimes it displays sometimes not.

import javax.swing.JApplet;
import javax.swing.JButton;


public class SimpleJApplet2 extends JApplet {

public void init() {
getContentPane().add(new JButton("Button One"));
}

}


But using event dispatching thread is recommended. What is wrong with the first piece of code?
[ November 19, 2004: Message edited by: Xinyi Zhang ]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if it is so much trouble to display an applet, then microsoft has really done something to the java movement.

I could display applet before, but not now. Under tools | internet options | advanced, for Microsoft VM, the checkbox for 'java console enabled' is unchecked, I could not check it. I am using win2000. Is this an admin issue?

Thanks
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually what you're doing is not really recommended. Building the GUI directly in the init() method ensures that the components will be assembled before the applet is painted. Building it in the Swing thread means that the components won't be placed until the applet has already been physically painted on the screen, blank. To make the components show up at that point, you'd need to explicitly validate the applet. You could add a call to validate() at the end of your run() method, and that would clear up the problem, or you could simply move the body of run() into init() and get rid of the Runnable altogether, as in your second example.

You are indeed supposed to use the event thread to make changes to the GUI after it's been physically displayed -- but then still, you have to call validate() to get the layout manager to force your changes into effect. So for example, if you had a separate animation thread, and it made changes to the GUI, then it should use the invokeLater() technique.
 
Xinyi Zhang
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Ernest. Your post is very helpful.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic