Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Displaying Java applet in browser via HTML

Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good afternoon everyone. I'm new to Java and currently in a class where I need to display (and test) my applet in a web browser using HTML code. I'm able to get the string of the test program to display on the browser, but not the actual window. I've placed the HTML inside a .html file in the same folder under the same class name as the program I'm trying to view, but am having no luck. The program compiles and displays the window when run through command prompt, but does not display in the browser. If anyone can point me in the right direction, I would greatly appreciate it! I've used my search engine tirelessly without luck.

Here is the HTML code I'm using (the string displays, but window does not):

Here is the program (I have a much longer program I'm trying to run, but decided to test a smaller one for debugging) -  and thank you in advance!:

Posts: 69847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't try strange colours of code like that; some people can only read certain colours.
What Applet? You are trying to extend JDialog, not JApplet. Why are you trying to use applets at all? They are obsolete. What sort of course have you got on?
You can run an applet via an html file which you open with the appletviewer tool, but youi don't have an applet. You will have to give it a main method. You will find more about it in the Java™ Tutorials.

Don't use System.exit. It might work in a single‑threaded environment, but you are here multi‑threading, so it can damage the integrity of anything used by other code. Don't catch IllegalArgumentExceptions; you cannot correct the error in code still running.
I once met a man from Nantucket. He had a tiny ad
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic