• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Applet dispaly problem

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • 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: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you, Ernest. Your post is very helpful.
 
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic