My very own component?

Posted on 2003-03-18
Medium Priority
Last Modified: 2010-03-31
Hiya everybody,

I've got a sort of component knocked together. Its sort of something like this:

   list box

In this class are functions that can be called and are already written inside here, they are only used on the list box and its contents. But I don't have a clue on anything on how to turn this into my own component. Also I don't really want a frame there if possible, just the list box by itself. The list box handles its own mouse events apart from one, which I would like to be handled by the class that creates an object of this component class.

Any help or pointers would be appreciated.
Question by:CPUCentral
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

FaithNoMore earned 110 total points
ID: 8163037
By extending ListBox (is ListBox even a class under java.awt?, I cant remember) your class is now a ListBox and you can add your custimized variables and methods + you get all of the current variables and methods that come with ListBox.  Be carefull you dont override the ListBox methods by mistake :)

I am currently at work so my syntax may be a little off.

public class MyListBox extends ListBox implements ActionListener
    static final int MYOWNVARIABLE = 1;    

    MyListBox( )
       // You can initialize your listbox here.

    // You can add you own event listeners here.


Author Comment

ID: 8173069
Ok I think I get what you mean, just another question...currently I have:

public class MyComponent extends java.awt.List{

However, when I use this class I also am able to access LOADS of other methods relating to the java.awt.list class that are just not needed. All I want to be available is the methods that I have defined in the class MyComponent.

Expert Comment

ID: 8173985
I dont think its possible.  Since List is a subclass of Component, it will receive all of the Components variables and methods and will add its own methods/variables.

When you make your class a subclass of List, you will receive all of the methods.

Someone correct me if I am wrong on this.
I dont think its possible to make a subclass of another class and only inherit the variables/methods you want.  I am pretty sure you get them all no matter what

To do what you are saying, you would probably have to not extend and other class and start from scratch.  Seemslike you want to do something that is already done for you and not very OOP.


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

800 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