Solved

Writing an Appletviewer

Posted on 1998-10-30
3
266 Views
Last Modified: 2012-06-27
As part of my first-semester Java programming class, my professor has assigned a project to write my own appletviewer in Java (either as an application or an applet itself).  He also is fairly new to Java and admits that he really has no idea how much we will be able to do or how much is possible to do through a normal applet or application.  
  First, I'd like to know any books or web sites that might contain code of an appletviewer or something similar.  Specifically, I have run into problems in three areas.      First, the professor suggested the following code:
   Applet theApp;
   theApp = new args[0];
   theApp.init();
to create an instance of the class file whose name is entered by the user and stored in a string variable (args[0]), and then to invoke the methods (init, paint, etc.) in that applet.  However, when compiling, an error message says the new operator doesn't work with string variables.  Is there a way to convert a string to a class name?
  Secondly, when invoking the applet's paint method from the appletviewer, a Graphics object has to be sent.  However, apparently a new Graphics object cannot be directly instantiated in the code.  Is there a way to send the applet's paint method a new frame or window as a parameter so that a new window pops up when the appletviewer runs the applet?
  Finally, the following code to take actions based on mouse movements was also suggested, but doesn't work:
   boolean done = false;
   while (!done) {
     ActionEvent event = await();
     switch(event) {
       case stop: theApp.stop(); break;
       case start: theApp.start(); break;
       case quit: done = true; break;
       default: action: action(event, obj);
      }
     }
    and implements MouseMotionListener in the class header.
  The problem may just be one of type declarations of these variables or wrong method names, or it may be totally off-base.  Would this code have to be in a special method of the appletviewer?  What would obj be?
  I know my questions are somewhat vague, since I am not yet very familiar with all the packages and classes embedded in the Java API.  If you just know some place that would have information useful to someone trying to write a simple appletviewer, I would be very grateful.
 
  Thanks!  
0
Comment
Question by:cms6204
  • 2
3 Comments
 

Author Comment

by:cms6204
Comment Utility
Adjusted points to 150
0
 
LVL 4

Accepted Solution

by:
rembo earned 150 total points
Comment Utility


Well, remember Applet extends Panel.  

So, if you create a Frame, put a panel in it and call
the init() and start() methods, you should have your
appletviewer.  

Hope that helps,

-Tony

0
 

Author Comment

by:cms6204
Comment Utility
Thanks for your help.  We have a more complicated version working fairly well without using Panel, but your idea seems like it should be simpler and probably more efficient.  However, I haven't used Panel before, and the reference manual I have just lists a constructor and method addNotify().  If you could give me a little more information on how Panel works, it'd be great;  but of course I'll give you the points in any event.

Thanks,

Chris
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now