Solved

Applet difficulty

Posted on 1997-03-11
1
294 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 100 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 86
spring jars download 1 28
How do I remove an object from a 3 27
going to wrong jsp page 2 21
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

803 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