Solved

Writing an Appletviewer

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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 first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

732 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