?
Solved

Writing an Appletviewer

Posted on 1998-10-30
3
Medium Priority
?
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:cms6204
ID: 1226729
Adjusted points to 150
0
 
LVL 4

Accepted Solution

by:
rembo earned 600 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

800 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