~/Blog

Brandon Rozek

Photo of Brandon Rozek

PhD Student @ RPI studying Automated Reasoning in AI and Linux Enthusiast.

Viewing Java Applets

Published on

Updated on

2 minute reading time

Warning: This post has not been modified for over 2 years. For technical posts, make sure that it is still relevant.

When you use an IDE there are many things you can take for granted. A section of an intro level computer science course at my university uses JGrasp to build Java Applets.

Following around using a normal text editor, I found that I couldn’t just compile and run the code like I have with my java programs in the past. To be able to help around and assist in the course, I need to be able to build and run these applications. The rest of this article describes the process I underwent to be able to use my existing setup to write and build java applets. Of course you can always install JGrasp and have that all built in, but it’s always nice to not have to change your workflow.

When I tried following along, I would receive the following error

Main method not found in class HelloWorld, please define main method as...

Which makes sense since I have never defined a main method inside my source code. So how do I go about doing this?

Setup

Java Applets are meant to run on web pages, because of this one needs an html file to host the applet. The following code gives you the bare minimum for setting up the html file. I called it HelloWorld.html.

Hello World Program

To get it up and running, I will show a “Hello World” like application for applets.

Running the Applet

Now we need to compile the code

Then run the appletviewer

Conclusion

This tutorial concludes the setup of running a simple Java applet. From here you can look at the different methods in the Graphics library and play around 😀

Reply via Email Buy me a Coffee
Was this useful? Feel free to share: Hacker News Reddit Twitter

Published a response to this? :