[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Makick a button?

Posted on 2000-01-25
4
Medium Priority
?
174 Views
Last Modified: 2010-04-01
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!
0
Comment
Question by:dvd99
  • 2
4 Comments
 

Expert Comment

by:amitd
ID: 2387159
ya u can do it boss
but what about the previous question u asked didnot allot points?
for answer?
0
 
LVL 3

Accepted Solution

by:
rjackman earned 160 total points
ID: 2387317
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
 
LVL 1

Author Comment

by:dvd99
ID: 2474141
Adjusted points to 40
0
 
LVL 3

Expert Comment

by:rjackman
ID: 2480596
thanx
RickyJackman
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question