• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MouseEvents/Listener

 
Robert Staniforth
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And for your own sake, learn how to use arrays. It will make your code much shorter and readable.
 
Robert Staniforth
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Robert Staniforth
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it, put this outside of the constructor

 
Robert Staniforth
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic