File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes MouseEvents/Listener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "MouseEvents/Listener" Watch "MouseEvents/Listener" New topic
Author

MouseEvents/Listener

Robert Staniforth
Greenhorn

Joined: Aug 03, 2010
Posts: 11
What the hell am I doing wrong here?

i really dont want to post my whole code here..but i suppose it's the only way haha


don't judge my comments, i haven't really been bothered with them yet haha.

My aim: Right click on label201, label203 (etcetc) = call method from a different class

I'm sure this will be a simple solution but it's doing my face in.. it says
" cannot find symbol variable label201 in class HotelGUI" and points at label201
i'm just using that System.out.println to test if it's working before i put the correct code I want in there

so if JLabel doesn't work then what do I use?

thanks a lot!
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4490
    
    8

On line 177 you're referring to label201. But label201 was locally declared in the constructor, so can't be accessed outside the constructor.

You can always declare label201 as a class member variable. You're then going to run into another problem. isMetaDown() returns a boolean - so how is it even going to equal a JLabel? That won't compile either. What are you trying to achieve there?

Robert Staniforth
Greenhorn

Joined: Aug 03, 2010
Posts: 11
oh yeah, didn't think about that..my head is done in haha, been doing this assignment all day

think i need a break

cheers mate
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

And for your own sake, learn how to use arrays. It will make your code much shorter and readable.


luck, db
There are no new questions, but there may be new answers.
Robert Staniforth
Greenhorn

Joined: Aug 03, 2010
Posts: 11
i'm following an assignment + i don't care about how long my code is or how readable tbf..
after i've done this assignment I never intend to look at or think about java ever again
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

Robert Staniforth wrote:after i've done this assignment I never intend to look at or think about java ever again

Be gone, ye heathen!

Seriously, that really won't stop us helping you. I do think that, if you are (going to be) a programmer, you're missing out. If a programming course is just part of the curriculum, well, not everyone wants to be a programmer. Although I can't understand why not


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Robert Staniforth
Greenhorn

Joined: Aug 03, 2010
Posts: 11
I always wanted to be a programmer when I was in secondary school then I touched base with Visual Basics in college, now I'm at uni I was really looking forward to Java but basically the University life effected me and I went to maybe 6 of the 70 lectures I had and 2 of the 35 tutorials.
When it came to doing the assignments I hadn't a clue what I was doing so I didn't bother trying with them, they gave me the opportunity to resit the assignments (which is what I'm doing now) and I really enjoy Java when I know what I'm doing.. not knowing certain code or how it works exactly really drives me insane. I'm amazed I've managed to do as much as I have considering my knowledge for it haha, 2 weeks ago I didn't even know what the f a class was!

My course doesn't continue it after the first year, although I'm sure there will be some programming somewhere along the line as I'm doing Forensic Computing haha.

I've just had a few hours break from it, gonna start again..I can't figure out how to make the JLabels into a "class member variable". I read up on it and you use "static".. i'm not really sure how to do it, trial and error has got me no where so far.
I tried
static JLabel label201 = new JLabel(blahblah);
The oracle.com tutorials don't really go into enough detail for my liking haha
Robert Staniforth
Greenhorn

Joined: Aug 03, 2010
Posts: 11
got it, put this outside of the constructor

Robert Staniforth
Greenhorn

Joined: Aug 03, 2010
Posts: 11
another issue i've got stuck on, when I left click it's supposed to clear the room using a method which i've sorted
but then when it's occupied I need the JLabel text to say "Occupied"
so i've put in the mouse event
if clicked on
String s203 = "occupied" or whatever

my guess::
it's changing it but it doesn't seem to re load because the .add for the panel is in HotelGUI constructor..
is there any way I can make it refresh the HotelGUI constructor?
or was my guess completely wrong
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> after i've done this assignment I never intend to look at or think about java ever again

I'm willing to spend some of my time trying to help you learn java,
but your sole interest seems to be just passing an assignment, and that's it for java.

In that case, there are sites that will do your assignment for you (for a fee),
and you'll never have to be bothered by java again.

Perhaps a google session will suit you better.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MouseEvents/Listener