Solved

Applet difficulty

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
factorial example challenge 10 61
countX 22 70
Spring Controller - inheritance in request parameter 3 38
Eclipse Neon and jdk 1.8.0 11 66
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now