aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes simple program but not able to get the required output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "simple program but not able to get the required output " Watch "simple program but not able to get the required output " New topic
Author

simple program but not able to get the required output

vamsi naki
Ranch Hand

Joined: May 18, 2011
Posts: 46
Hi,
i wrote a simple code that changes the color of the frame when the button is clicked ,the thing is when i run the program i am getting the output of the previous program (a frame that just displays a button) which i wrote .I am using eclipse indigo .Eclipse says there is an error in the project but where the error is it is not showing.

Shtilmark Pollo
Greenhorn

Joined: Jun 14, 2012
Posts: 4
I think your code must be something like that:
Hitesh P Patel
Greenhorn

Joined: May 23, 2012
Posts: 8
vamsi naki wrote:when the button is clicked


How you are getting Button in frame without adding it to container ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Eclipse should always show you where the error is, with a little red icon with a cross in. Hover your mouse over that and you get more details. What it cannot tell you is whether you are using object‑oriented design or not, and that isn’t even close! In my opinion addActionListener(this) is an abomination against object‑oriented programming, and all the people who write books using it ought to be strung up and beaten with several megabytes of C code

Start here. You will want some sort of class. How about this?There are obviously bits you will have to fill in for yourself. Search for my posts on this forum with “ColourListener” as a keyword, and you will find more. But I don’t think you will find a complete class.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Welcome to the Ranch Shtilmark Pollo.

If you are using the action command without setting it, won’t you suffer a null pointer exception?
Shtilmark Pollo
Greenhorn

Joined: Jun 14, 2012
Posts: 4
Campbell Ritchie wrote:Welcome to the Ranch Shtilmark Pollo.

Gracias
Campbell Ritchie wrote:
If you are using the action command without setting it, won’t you suffer a null pointer exception?

I dont think so. If action command not set then getActionCommand return button text.
From javax.swing.AbstractButton
vamsi naki
Ranch Hand

Joined: May 18, 2011
Posts: 46
Hitesh P Patel wrote:
vamsi naki wrote:when the button is clicked


How you are getting Button in frame without adding it to container ?



i should have checked i forgot to add the buttons to the container


Thanks Campbell Ritchie ,Shtilmark Pollo and Hitesh P Patel .I have to go through a lot of topics in GUI i guess,cause i dont know anything about ColourListener.I will refer to your posts Campbell Ritchie.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simple program but not able to get the required output
 
Similar Threads
buttons
Java Newbie needs guidance
Getting the TwoButtons to add the gradient circle to the panel
Basic swing application; class extending JPanel won't update graphics
Buttons and action events