Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ActionListener and Event

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why doesn't the following simplification work?

Before



After - Tried adding a makeButton() method...


Sourced and adapted from Core Java Vol I p. 331-332.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't see anything wrong with it. The background changed colour when I clicked the buttons.

Moving to our GUIs forum.
 
Jared Malcolm
Ranch Hand
Posts: 54
Java MySQL Database PHP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgot a couple things around here...

(These two lines)
Also yellowButton is used twice here, but mainly you didn't get the ContentPane and then add the JPanel to it.
 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jared Malcolm wrote:Forgot a couple things around here...

(These two lines)
Also yellowButton is used twice here, but mainly you didn't get the ContentPane and then add the JPanel to it.


How would it work?
 
Jared Malcolm
Ranch Hand
Posts: 54
Java MySQL Database PHP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jon Camilleri wrote:How would it work?


Not sure I understand this question?...I took your second block of code and looked through it.....what APPEARED to be the issue is that you never retrieved the content pane and then added the panel to that...

I say appeared as I added the two lines of code and it functioned.

The second code block was just adding in that you listed yellow twice so you would have only ever gotten two buttons.



This is the code that I ended up with...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic