Solved

Writing an Appletviewer

Posted on 1998-10-30
3
268 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
ID: 1226729
Adjusted points to 150
0
 
LVL 4

Accepted Solution

by:
rembo earned 150 total points
ID: 1226730


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
ID: 1226731
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mockito example issue 8 73
egit plugin on eclipse 8 64
servlet filter example 37 63
ejb on wildfly 5 20
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

809 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