Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Applet difficulty

Posted on 1997-03-11
1
Medium Priority
?
311 Views
Last Modified: 2012-05-04
I am having difficulty with applets I am using. Both of the applets I wish to use require more than one ".class" file, but there doesn't seem to be anywhere where the first calls the second or refers to the second. eg an applet which is supposed to allow the user to change text color and bgcolor but does not, a default color seems to always come up. Looking at the code, the class file which has reference to bgcolor etc is in "thoughts.class", actual paraname values which can be changed are in a separate class file. Both class files are in the same directory but the bgcolor and text color values do not change to the required input. The same happens with the LivingLinks.class. There is a Fade.class plugin for this applet, but I am unable to  get it to work.
Any suggestions would be appreciated.

Thanks,  Craig
0
Comment
Question by:craigo
1 Comment
 
LVL 1

Accepted Solution

by:
tatti earned 200 total points
ID: 1218990
Let's see if I understood this correctly. You have an applet that consists of multiple classes. The applet class receives color information from applet parameters, or where ever.

The problem is that you have another class which draws stuff on the applet and it should get to know the colors to use. You can either make the colors class or instance variables (static or normal).

If you make them static, you can refer to them from the other class as "AppletClass.FOREGROUNDCOLOR". If they are normal instance variables, you will need to tell the other class's instance where the applet instance is located. Here's a dummy example of the latter:

import java.applet.Applet;
import java.awt.*;

class Test extends Applet {
  Color fore,back;
  Inner in;
  public void init() {
    in=new Inner(this);
  }
  public void paint(Graphics g) {
    in.paint(g);
  }
}

class Inner {
  Test myowner;
  public Inner(Test owner) {
    myowner=owner;
  }
  public void paint(Graphics g) {
    g.setColor(myowner.fore);
    g.drawString("Greetings from Inner class",10,10);
  }
}

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

916 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