Makick a button?

Hello in AWT to add a button you add this code :
Button b = new Button("Button");
add(b); // and in swing you add a J before the Button.
This makes a very boaring button but you can change the buttons background by setting a background color to it.
The question i have is , is there a way I can make my own button called say OButton and when ever i add the code obutton = o new obutton("Orange") it will have a orange background?
Thanks!! This would have to have all the same events as a Button (Everything the same but different bg color)
Thanks!
LVL 1
dvd99Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

amitdCommented:
ya u can do it boss
but what about the previous question u asked didnot allot points?
for answer?
0
rjackmanCommented:
WHY NOT U CAN JAVA IS A OBJECT ORIENTED LANGUAGE
SO U CAN CREATE UR OWN CLASSES AND CAN REUSE THEM.

HERE IS THE CODE For CLASS U WANT
IN THE CONSTRUCTOR OF Obutton IT ACCEOTS THE COLOR OBJECT
MAKE SURE THAT IT IS A VALID COLOR WHILE SETTING
import java.awt.*;
import java.awt.event.*;

public class Obutton extends Button
{
      private Color col;
      public Obutton(Color c)
      {
            this.col= c;
            this.setBackground(c);
      }
            
}

TO USE THIS CALSS HERE IS A SAMPLE CODE THAT IF U WANT
CAN TRY

WHAT I AM DOING HERE IS i have CREATED A Color object c
 AND THAT I AM PASSING C.ORANGE TO CONSTRUCTOR
U CAN SET THE COLOR OF UR CHOICE BY THIS WAY
C = new Color(INT,INT,INT);

import java.awt.*;
import java.awt.event.*;


public class demoBut implements ActionListener
{
      private Obutton but;
      private Frame f;
      private Color c;
      public demoBut()
      {
            but = new Obutton(c.orange);
            but.addActionListener(this);
            f = new Frame("DEmoJAVA");
            f.setSize(300,150);
            f.add(BorderLayout.CENTER,but);
            f.setVisible(true);

      }
      public void actionPerformed(ActionEvent ae)
      {
            but.setBackground(Color.blue);

      }
      public static void main(String args[])
      {
            demoBut  but = new demoBut ();

      }

}
BEST LUCK
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dvd99Author Commented:
Adjusted points to 40
0
rjackmanCommented:
thanx
RickyJackman
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.