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 ActionListener and Event Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ActionListener and Event" Watch "ActionListener and Event" New topic
Author

ActionListener and Event

Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

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.

Jon
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38821
    
  23
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

Joined: May 02, 2011
Posts: 54

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.


SCJA 6 (Studying for SCJP 6)
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

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

Joined: May 02, 2011
Posts: 54

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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ActionListener and Event