wood burning stoves*
The moose likes Applets and the fly likes applet trouble here Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "applet trouble here" Watch "applet trouble here" New topic
Author

applet trouble here

Shane McKenzie
Greenhorn

Joined: Jun 24, 2002
Posts: 10
I'd like to know why this won't work; it seems as though it should...I overrode the init() method so that the user can type a choice in JOptionPane, and that works when the html file is opened, but then regardless of user input, NO drawing elements appear! My sanity is slipping.....

HTML:

<HTML>
<applet code = Test.class width = 200 height = 200>
</applet>
</HTML>

Applet file:

import java.awt.*;
import java.applet.Applet;
import javax.swing.JOptionPane;

public class Test extends Applet
{
//data fields
private String shapeChoice;

public void init()
{
shapeChoice =
JOptionPane.showInputDialog( "Please enter C, S, or R:" );
}

public void paint(Graphics g)
{
if (shapeChoice == "c")
{
g.setColor(Color.black);
g.drawLine(0, 0, 100, 100);
}

else if (shapeChoice == "r")
{
g.setColor(Color.black);
g.drawLine(0, 0, 50, 50);
}

}

}// end class test

Any help here would be greatly appreciated!

shane


I've been trying to change the world for years, but they just won't give me the source code.
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
This may be too easy, but I noticed you compare Strings using "==", which checks to see if both Strings are the same object. You need to use one of the String equals methods. Try choice.equalsIgnoreCase("C") and see if that helps. (Check the String API to make sure I spelled it right!)
[ November 09, 2004: Message edited by: Jeff Bosch ]

Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Shane McKenzie
Greenhorn

Joined: Jun 24, 2002
Posts: 10
Thanks Jeff, I appreciate the help. Such a rookie mistake, but there ya go! Anyway, that seems to have worked ok, it runs properly now. Thanks again mate!
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
You're quite welcome, Shane. I made that mistake more than once when I was first learning Java. Now I always start debugging by looking for the easy stuff.

By the way, very cool sig. I got a good laugh out of that!
[ November 09, 2004: Message edited by: Jeff Bosch ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: applet trouble here
 
Similar Threads
Problem with inter-applet communication
Need help on two compile errors
How to edit security policy
Grid Alignment and Null Exception
applet help please