Solved

Writing an Appletviewer

Posted on 1998-10-30
3
267 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java array passed to SQL where clause 23 63
compre toata in where clue oracle 4 56
Groovy:unable to resolve class error 2 70
what is a "java.lang.System Property"   ? 20 57
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…
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

920 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