JLabels with MouseListeners

my teacher gave us an assignment to do

he gives us what he calls "starter code" and makes us use his starter code

in our own code. sounds good? the thing is one of the lines he has does not

make sense to me.

in a method that is in a class that extends mouseadapter

mouseClicked

the first line of code he has is

JLabel label = (JLabel) e.getComponent();

um... im assuming that if my code of

String x = label.getText();

would give me the string that is on the JLabel

however, i get an error instead

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException

and since i am not aloud to change his code,

i am forced to learn a way to go about getting the contents of a JLabel when i click it using his starter code.

[814 byte] By [apple_ipoda] at [2007-10-2 6:44:43]
# 1

just suppose that the variable "e" is one of these

[url http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/MouseEvent.html]mouse event[/url]

you will find it's methods in the previous link.

here is the doc for JLabel

[url http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JLabel.html]JLabel[/url]

you won't have any luck casting an event to one of these

sincerely

Walken

walken16a at 2007-7-16 13:53:13 > top of Java-index,Java Essentials,New To Java...
# 2
This topic is being continued here[url http://forum.java.sun.com/thread.jspa?messageID=4004521]new thread[/url]
walken16a at 2007-7-16 13:53:13 > top of Java-index,Java Essentials,New To Java...