Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with mouse listeners and color objects  RSS feed

 
Robert Stannis
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, I want a red circle to appear in the top left. When I click it I want it to change locations and colors, basically moving around in a circle.

http://pastebin.com/0c7Apyyy

I need help with the value of the color. How do I change it? I also can't seem to get the circle to move, so if you could point out what I did wrong with the listener class I'd be grateful.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a lot of folks here can't or won't go to a third party site to look at your code. Generally, we like it when you can post the relevant code here that illustrates your problem. It should be complete and compilable by anyone who can cut-n-paste it into their IDE.

Make it as easy as possible for folks to help you, and your chances of getting that help improves dramatically.
 
Robert Stannis
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:a lot of folks here can't or won't go to a third party site to look at your code. Generally, we like it when you can post the relevant code here that illustrates your problem. It should be complete and compilable by anyone who can cut-n-paste it into their IDE.

Make it as easy as possible for folks to help you, and your chances of getting that help improves dramatically.




No problem.
 
Joel Christophel
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at your last else-if block. There's something quite unwanted there. As for changing colors, you can assign c to a different color object every time you click. You can either use predefined colors, such as Color.RED or you can use a website like this to choose a color of your fancy.
 
Robert Stannis
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joel Christophel wrote:Look at your last else-if block. There's something quite unwanted there. As for changing colors, you can assign c to a different color object every time you click. You can either use predefined colors, such as Color.RED or you can use a website like this to choose a color of your fancy.


What syntax do I use to change the value of c in the statements?
 
Joel Christophel
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert Stannis wrote:What syntax do I use to change the value of c in the statements?


It's the same thing as assigning an int or String variable:

<Variable name> = <value or Object>

So what is your variable name? And what's one way of getting a color object? (Hint: you've already done it in your program)
 
Robert Stannis
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joel Christophel wrote:
Robert Stannis wrote:What syntax do I use to change the value of c in the statements?


It's the same thing as assigning an int or String variable:

<Variable name> = <value or Object>

So what is your variable name? And what's one way of getting a color object? (Hint: you've already done it in your program)


Updated code




I added the color values for each one, but every time I click it changes to blue. Also, am I handling the coordinates right? Because I can't get the circle to change location.
 
Joel Christophel
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's still something wrong with your last else-if block. There's one extra character that's causing you problems.
 
Robert Stannis
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joel Christophel wrote:There's still something wrong with your last else-if block. There's one extra character that's causing you problems.


Hah, got it! I stared at it for 10 minutes.

Thanks for your help.
 
Joel Christophel
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert Stannis wrote:
Joel Christophel wrote:There's still something wrong with your last else-if block. There's one extra character that's causing you problems.


Hah, got it! I stared at it for 10 minutes.

Thanks for your help.


Nice. No problem.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a related not, if you are using Swing (JApplet is the swing equivalent of the AWT applet), you should override paintComponent(Graphics g) instead of paint(Graphics g)
UI related questions are best suitable on the UI forums. Moving...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!