Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

572 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