• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ActionListener and Event

 
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79153
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 54
MySQL Database PHP Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database PHP Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic