Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple program but not able to get the required output

 
vamsi naki
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your code must be something like that:
 
Hitesh P Patel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vamsi naki wrote:when the button is clicked


How you are getting Button in frame without adding it to container ?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49772
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49772
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic