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
Solved

Applet difficulty

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

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

Suggested Solutions

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

808 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