Question about extending classes

Hi
I've created my own class that extends javax.swing.JTextField as follows:
public class myTextField extends javax.swing.JTextField{
     public myTextField(){
          super();
          initialize();
     protected void initialize()
          super.setEditable(false);
          super.setHorizontalAlignment(javax.swing.JTextField.LEFT);
          super.setBorder(null);
          super.setSelectionColor(null);
}Dunno if this is the best way to do it, but it works, so I'm happy!
My question is: Is it possible to have more than one definition in this class?
For example, a myTextField2 that extends JTextField with completly different attributes (eg, different back ground colour etc) or do I have to create a new class?

For example, a myTextField2 that extends JTextField
with completly different attributes (eg, different
back ground colour etc) No, but you can create another constructor that accepts different arguments.
public myTextField(Color c)Like that. By the way class names should start with an upper-case character.

Similar Messages

  • A question about Object Class

    I got a question about Object class in AS3 recently.
    I typed some testing codes as following:
    var cls:Class = Object;
    var cst:* = Object.prototype.constructor;
    trace( cls === cst); // true
    so cls & cst are the same thing ( the Object ).
    var obj:Object = new Object();
    var cst2:* = obj.constructor.constructor;
    var cst3:* = obj.constructor.constructor.c.constructor;
    var cst5:* = Object.prototype.constructoronstructor;
    var cst4:* = Object.prototype.constructor.constructor.constructor;
    var cst6:* = cls.constructor;
    trace(cst2 === cst3 && cst3 === cst4 && cst4 === cst5 && cst5 === cst6); //true
    trace( cst == cst2) // false
    I debugged into these codes and found that cst & cst2 had the same content but not the same object,
    so why cst & cst2 don't point to the same object?
    Also, I can create an object by
    " var obj:Object = new cst();"
    but
    " var obj:Object = new cst2();"
    throws an exception said that cst2 is not a constructor.
    Anyone can help? many thanks!

    I used "describeType" and found that "cst2" is actually "Class" class.
    So,
    trace(cst2 === Class); // true
    That's what I want to know, Thank you.

  • Question about extend calendar using scal?  help,help

    recently, we received a mail from sap which saying about extending  calendar using scal;
    I have read sap notes:1529649 , 501670
    and my steps will be:
    1> in our qas system using scal
        change holiday calendar: choose CN China holiday calendar to change and then enter validation from 1995 to 2098(for example)
    2> change factory calendar: choose CN China factory calendar to change and then enter validation from 1995 to 2098(for example)
    3> in scal , choose menu: extras-->update calendar buffer
    4> transport this change to our prd system.
    5> go to scal in prd system to check
    6> update prd system `s calendar buffer in scal
    I do know whether my steps is right?
    I have two questions:
    1> we are a chinese compary, and we use several languages:TRADITIONAL CHINESE , SIMPLIFIED CHINESE and ENGLISH;
         whether i should change other holiday calendar,such as british calendar?
    2> Is there something wrong about my steps?
    thanks a lot.
    Edited by: victor on Nov 29, 2010 6:17 AM

    Hi,
    You are correct, But You can change it on QAS due to client will not modifiable.
    Goto Developement System and run scal.
    Most important is to change/extend factory calander and save it. Request will be generated as Workbench. Transport it to Production System.
    Rgds
    dk

  • Question about inner class - help please

    hi all
    i have a question about the inner class. i need to create some kind of object inside a process class. the reason for the creation of object is because i need to get some values from database and store them in an array:
    name, value, indexNum, flag
    i need to create an array of objects to hold those values and do some process in the process class. the object is only for the process class that contains it. i am not really certain how to create this inner class. i tried it with the following:
    public class process{
    class MyObject{}
    List l = new ArrayList();
    l.add(new MyObject(....));
    or should i create the object as static? what is the benifit of creating this way or static way? thanks for you help.

    for this case, i do need to create a new instance of
    this MyObject each time the process is running with a
    new message - xml. but i will be dealing with the case
    where i will need a static object to hold some
    property values for all the instances. so i suppose i
    will be using static inner class for that case.The two situations are not the same. You know the difference between instance variables and static variables, of course (although you make the usual sloppy error and call them static objects). But the meaning of "static" in the definition of an inner class is this: if you don't declare an inner class static, then an instance of that inner class must belong to an instance of its containing class. If you do declare the inner class static, then an instance of the inner class can exist on its own without any corresponding instance of the containing class. Obviously this has nothing to do with the meaning of "static" with respect to variables.

  • Question about abstract classes and instances

    I have just read about abstract classes and have learned that they cannot be instantiated.
    I am doing some exercises and have done a class named "Person" and an abstract class named "Animal".
    I want to create a method in "Person" that makes it possible to set more animals to Person objects.
    So I wrote this method in class Person and compiled it and did not get any errors, but will this work later when I run the main-method?
    public void addAnimal(Animal newAnimal)
         animal.add(newAnimal);
    }Is newAnimal not an instance?

    Roxxor wrote:
    Ok, but why is it necessary with constructors in abstract classes if we don�t use them (because what I have understand, constructors are used to create objects)?Constructors don't create objects. The new operator creates objects. An object's c'tor is invoked after the object has already been created. The c'tors job is to initialize the newly-created object to a valid state. Whenever a child object is created, the parent's c'tor is run before the child's c'tor, so that by the time we're inside the child's c'tor, setting up the child's state, we know that the parent (or rather the "parent part" of the object we're initializing) is in a valid state.
    Constructor rules:
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

  • Questions about Extended classic scenario

    Hi gurus,
    I'm working in SRM 5.0, ECS, backend ECC 6.0 (only one backend).
    Everytime a SC is being approved a SRM PO has be created. Then a copy of this PO  has to be created in ECC with document Type ATT and the same number of the SRM PO.
    I have two questions
    First of all I need to know the settings to make in 'Define objects in backend system' (for every purchasing Group and every Category ID, I need to create always PO in backend).
    P.Gr   Category ID  Source System      Internal proc.                              External proc.
            *                 TRDCLNT011         Always external procurement        PO if item data complete, otherwise P.Req.
    Is this correct?
    Secondly I need to understand the logic for number range definition
    SRM Activities
    1 - Define number range for Shopping Cart
    I Need to create a SC number range
    01 1000000000 - 1999999999
    and then associate this range (01) to SHC transaction type ('Int.n' field)
    2 - Define a number range for local PO
    LO 7000000000 - 7999999999
    and then associate this range (LO) to ECPO transaction type ('Int.n' field)
    3- Create a new transaction type 'ATT' (backend PO)
    4 - Define a number range for backend PO
    PO 7000000000 - 7999999999
    and then associate this range (PO) to ATT transaction type ('Int.n' field)
    ECC Activities
    1 - Define a number range for document type ATT
    XX 7000000000 - 7999999999
    and then associate this range (XX) to ATT Document  type 'External
    Is this correct?
    I'd really appreciate your help
    Points will be rewarded
    Thaks in advance
    Best regards
    Gg

    Hi. It all sounds about right.
    I don't think the define backend docs does a great deal in ECS, you always get a PO with extended classic. If you ever want anything but a PO, a reservation for example, you have to not use extended classic for those items.
    The number ranges look OK, although I think you only need 1 number range for the backend/local POs, it should all go in line on its own. It's been a while since I got an ECS system going so it is hard to remember.
    The thing to do is try it in a test system and see what happens.
    If anything goes wrong let us know on SDN what error messages you get and we should be able to help.
    Regards,
    Dave.

  • Question about multiple classes and Linked Lists

    Lets say you have 4 classes: LinkedList which is the main class, Node, Card, and Hand. im not putting any constructors yet
    The card class keeps track of a card such as a king of diamonds:
    public class Card {
    string suit;
    string rank;
    the node class has a Card object and another node object so it would be
    public class Node {
    Card c;
    Node next;
    the hand class keeps track of the users hand. This program will ask the user if they want to add, remove, print out the hand, or print out the score of the hand, I guess it would be like this
    public class Hand {
    Node head;
    The linkedlist class will contain all the methods for doing the above
    now my questions are. Lets say I want to add a card, so I would have to add a new Node which contains the card. If i wanted to access the new nodes card contents, lets call this node g, can i do, g.c.suit and g.c.rank in which this case c is the card object in Node. Also, these are not going to be nested classes, they are going to be 4 seperate classes, if I declare all variables as private will I need to extend the classes or not and if there is a better way, let me know. Thanks alot for all your help and previous help.

    here is an example of Card and Hand ...
    not saying its good design
    but it does work
    public class Cards {
    public static void main(String[ ] args) {
    Card c1 = new Card ("ace", "diamonds");
    Card c2 = new Card ("two", "spades");
    Card c3 = new Card ("three", "hearts");
    Hand a1 = new Hand ();
    a1.add(c1);
    a1.add(c2);
    a1.add(c3);
    System.out.println("\nshowing hand ...");
    a1.show();
    System.out.println("\ndeleting " + c2.num + " " + c2.suite);
    a1.del(c2);
    System.out.println("\nshowing hand ...");
    a1.show();
    } // main
    } // class
    class Hand exists in 3 states
    and is designed to be a chain of cards ...
    1. when class Hand is first created
       a. it has no card
       b. and no nextHand link
    2. when somecard is added to this Hand
       a. it has a card
       b. and the nextHand link is null
    3. when somecard is attempted to be added to this Hand
       and it already has a card
       then a nextHand is created
       and the somecard is added to the nextHand
       a. so the Hand has a card
       b. and the Hand has a nextHand
    class Hand {
    public Card acard;
    public Hand nextHand;
    public Hand () {
      acard = null;
      nextHand = null;
    public void add (Card somecard) {
      if (acard == null) {
        acard = somecard;
        return;
      if (nextHand == null) nextHand = new Hand();
      nextHand.add (somecard);
    delete this Hand by making this Hand
    refer to the next Hand
    thus skipping over this Hand in the nextHand chain
    for example, removing Hand 3 ...
    1  -  2  -  3  -  4   becomes
    1  -  2  -  4
    public void del (Card somecard) {
      if (acard == somecard) {
        if (nextHand != null) acard = nextHand.acard;
        else acard = null;
        if (nextHand != null) nextHand = nextHand.nextHand;
        return;
      nextHand.del(somecard);
    public void show() {
      if (acard == null) return;
      System.out.println(acard.num + " " + acard.suite);
      if (nextHand != null) nextHand.show ();
    } // class
    class Card {
    public String num;
    public String suite;
    Card (String num, String suite) {
      this.num = num;
      this.suite = suite;
    } // class

  • Two questions about defining class, pls help me

    Hi, guys. I'm green hand and here are two questions puzzled me several days.
    We know such example as below is a case of cyclic inheritance
    class Base extends Base{     
    But I can't figure out why below is a case of cyclic inheritance too
    class Base{
    class Derived extends Base{
    class Base{
    I can't find the clue of cyclic inheritance. It's quite different from the case that a class extends itself or its subclass.
    Another question is why the inner class can't have the same name of outer?
    class Base{
    class Base{          
    The compiler says Base is already defined in unnamed package. As it says, the inner class is defined in the
    unnamed package, but we know below is correct.
    class Base{
    class Basic{          
    class Derived {
    class Basic{
    We know it's correct. But as the compiler says above, the different two inner class Basic are both defined in the
    unnamed package. Why it's valid and why above is invalid?

    Hi,
    Can you tell us which product (s) you are referring to ? Can you also tell us the nature of your business requirements so that we can offer some suggestions ?
    Regards,
    Sandeep

  • Not so trivial question about extending a wireless network

    Hello,
    I've always had Wi-Fi signal strength issues in my house. Two days ago my Linksys router died and I got the new AirPort Extreme. Things got a bit better signal wise. Feature wise things got a whole lot better! Which got me thinking about the next step.
    The two farthest corners of my hose are wired with CAT5E, and I have a gigabit router. My AirPort Extreme is on one of these corners, meaning I have a weak signal on the other corner. My question is, can I add another AirPort Extreme to the other corner, hook it on the wired LAN and have it extend my wireless network? I don't want to see 2 different networks. I want to see just my wireless network and have a strong signal everywhere. Can this be done?

    Actually a Linux server is my internet connection (has two NICs). All the computers in my house plug into a Gigabit hub. The AirPort express is configured as "Share a public IP address", instead of "Bridge Mode", because I want to be able to use the "Guest Network" feature (so cool!). Yes I have two DHCP/NAT servers, but they don't interfere with each other, as they are on separate networks. My main network is 192.168.1, my AirPort network is 192.168.2, and my Guest Network is 10.0.42.
    I will try both your suggestions and report back. It would be perfect if I could just plug the second AirPort to the Gigabit hub, but I don't mind chaining it to the first AirPort, if that's what it takes.
    This is turning out to be a really fun project and I might finally fix the wireless signal in my house after all these years
    Thanks!
    Erasmo.

  • Questions about Extending Active Directory Schema

    We have about 24 Macs at the moment in the environment and we are starting to look at Extending the Active Directory Schema.  I have been doing a lot of reading over the past few weeks and I think that I am more confused the more I research it.  The Windows Servers here are running Server 2008_R2.  So here are my questions:
    1. If we extend the schema does that mean that we do not need an OS X Server?
    2. Is this really the easiest option to go with?
    3. We are looking to be able to apply GPOs to the Macs through Active Directory so will this accomplish it?
    4. Will this also allow Group Policy Preferences to map printers to the Macs automatically too?
    5. Is this the least expensive option?
    6. What is the best way to convince the Windows Administrators that this is how we should proceed?
    Thanks
    Pads

    Hi
    1. Yes. However OSX Server offers far more than MCX or Mac-Style GPOs. NetBoot, SUS, Wiki are some you should be looking at IMO.
    2. Again IMO not really. It takes a lot of work and you really don't want to be doing this on a 'live' server. Set up a lab environment first, thoroughly test it and then go with it when you're happy. The other possible 'gotcha' is you will have no way of knowing if Microsoft decide to change/amend or extend their own proprietary schema in a Revision update sometime in the future. If that does happen then you may be looking at doing it all over again?
    3. Yes, but you will still need WorkGroup Manager installed on a mac client. The documentation is clear about what to do once the Schema has been extended.
    4. Not done this myself but I would think so.
    5. Yes, but is it the 'best' option? Not in my opinion.
    6. Offer them the 'easier' but more expensive alternatives (some of them very expensive) and see which way they jump.
    HTH?
    Tony

  • Question about nested classes

    Hi, i currently have the following problem:
    I have 2 classes, one of which also has a nested class:
    1. Home.java (extends JApplet)
    2. Away.java (extends JPanel) has nested class, private class ButtonListener implements ActionListener
    Now in Home.java I have a Vector ( called bankaccount) which i pass to the Constructor of Away.java ( I declared the vector again there as an instance by Private Vector bankaccount;).
    My problem is that in ButtonListener I am trying to access the Vector so that i can modify it when a button has been clicked, and i thought i could just use the commands of bankaccount.add() and bankaccount.get() directly, however it seems like ButtonListener cannot access the Vector, even though i passed it along to the Constructor of the Away class.
    Any suggestions on how i get access the Vector from the ButtonListenere class?

    This is an example:
    public class Home extends JApplet
    private Away away;
    private Vector bankaccount;
    public void init()
         bankaccount = new Vector();
         away = new Away(bankaccount);
    public class Away extends JPanel
    private Vector bankaccount;
    JTextArea text1= new JTextArea(50,50);
    public Away(Vector bankaccount)
       //declare buttons,textarea,setLayout,etc
    button1.addActionListener (new ButtonListener());
    //i can set  text1.setText(( String)bankaccount.get(0));
    // here to access bankaccount, and it shows up fine, but i want
    // do it in from the class below
    private class ButtonListener implements ActionListener
              public void actionPerformed(ActionEvent event)
                         //trying to access bankaccount here by doing:
                        // but it is not doing anything
                        text1.setText(( String)bankaccount.get(0));
    }

  • A question about calling classes

    Hi,
    I have a question regarding software design so that each class is independent of other.
    public class A
        public void methodA()
                 B m_B=new B();
              String strA=m_B.getBString();
              System.out.println(strA);
    public class B
       public String getBString()
                      return "someString";
    }My question: Is it possible to call the method in class B from class A without creating an instance of class B in method of class A ?
    I am trying to figure out if this can be done using interfaces and abstract classes.
    I am waiting for some suggestions and if you have completely different suggestion then I am open for it too.
    thanks in advance,
    @debug.

    interface I {
        String getString();
    class B implements I {
        public String getString() { return "someString";}
    class A {
        private I foo;
        public void setFoo(I foo) {this.foo = foo;}
        public I getFoo() {return foo;}
        public void methodA() {
          System.out.println(getFoo().getString());
    public class Main {
        public static void main(String[] args) {
            A a = new A();
            a.setFoo(new B());
            a.methodA();
    }There's one problem with decoupling A and B in this case - A's method creates an instance of B. The above is one solution. There are many others.

  • (newbie) Question about replacing .class files and web.xml file

    I'm new to servlets and I have two quick questions...
    Do I absolutely need a web.xml file to define all my servlets, or can I simply place .class files into the WEB-INF directory and expect them to run?
    If my application server (for example Tomcat) is running and I replace a servlet .class file, do I need to restart the server for the new .class file to take effect?
    ...or are both of these questions specific to the application server I'm using?

    Hi,
    From an article I read:
    With Tomcat 3.x, by default servlet container was set up to allow invoking a servet through a common mapping under the /servlet/ directory.
    A servlet could be accessed by simply using an url like this one:
    http://[domain]:[port]/[context]/servlet/[servlet full qualified name].
    The mapping was set inside the web application descriptor (web.xml), located under $TOMCAT_HOME/conf.
    With Tomcat 4.x the Jakarta developers have decided to stop allowing this by default. The <servlet-mapping> tag that sets this mapping up, has been commented inside the default web application descriptor (web.xml), located under $CATALINA_HOME/conf:
    <!-- The mapping for the invoker servlet -->
    <!--
    <servlet-mapping>
    <servlet-name>invoker</servlet-name>
    <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>
    -->
    A developer can simply map all the servlet inside the web application descriptor of its own web application (that is highly suggested), or simply uncomment that mapping (that is highly discouraged).
    It is important to notice that the /servlet/ isn't part of Servlet 2.3 specifications so there are no guarantee that the container will support that. So, if the developer decides to uncomment that mapping, the application will loose portabiliy.
    And declangallagher, I will use caution in future :-)

  • A question about Abstract Classes

    Hello
    Can someone please help me with the following question.
    Going through Brian's tutorials he defines in one of his exercises an  'abstract' class as follows
    <ClassType ID="MyMP.MyComputerRoleBase" Base="Windows!Microsoft.Windows.ComputerRole" Accessibility="Internal" Abstract="true" Hosted="true" Singleton="false">
    Now I am new to authoring but get the general concepts, and on the surface of it, it appears odd to have an 'abstract' class that is also 'hosted' I understand and abstract class to be a template with one or more properties defined which is then used
    as the base class for one or more concrete classes. Therefore you do not have to keep defining the properties on these concrete classes over and over as they inherit the properties from their parent abstract class, is this correct so far?
    if the above is correct then it seems odd that the abstract class would be hosted, unless (and this is the only way it makes sense to me) that ultimately (apart from singleton classes) any class that is going to end up being discovered and
    thereby an instance of said class instigated in the database must ultimately be hosted somewhere, is that correct?
    in other words if you has an abstract class, which acts as the base class for one or more concrete classes (by which I mean ones for which you are going to create lets say WMI discoveries ), if this parent abstract class is not ultimately
    hosted to a concrete class of its own then these child concrete classes (once discovered) will never actually create instances in the database.
    Is that how it is?
    Any advise most welcome, thanks
    AAnotherUser__
    AAnotherUser__

    Hi,
    Hosting is the only relationship type that doesn't require you to discover it with a discovery rule. OpsMgr will create a relationship instance automatically for you using a 'hosted' properties 'chain' in a class\model definition. In an abstract class definition
    you need to have this property set to 'true' or you will 'brake' a hosting 'chain'.
    http://OpsMgr.ru/

  • Question about Abstract Classes and Class Inheritance

    The semester is winding down, and the assignments are getting more complicated....
    Prof has given us a project involving both an interface and an abstract class. There's a class Person, then an abstract class Employee that extends Person, and two types of Employees (Hourly and Salaried) that extend Employee. The finished assignment is a type of payroll program that's supposed to be able to store both types of Employees and related info (name, salary, etc). One thing the prof suggested was to store both HourlyEmployees and SalariedEmployees in an array of Employees. But you can't instantiate an array of Employees directly, of course, since it's an abstract class.
    So is it possible to create an array of Persons, cast either HourlyEmployees or SalariedEmployees into Employee objects, and then store the Employee objects in the Person array? And if I do that, can I still use methods particular to the SalariedEmployees and/or HourlyEmployees once they are in the Person array? Or can I store SalariedEmployee and HourlyEmployee directly in an array of Persons, without having to cast them into anything else? (In that case, I'm not sure what the point of having the abstract Employee class is, though). Do they become just generic "Persons" if I do this?
    Thanks for any help!

    But you
    can't instantiate an array of Employees directly, of
    course, since it's an abstract class.Sure you can. You just can't instantiate Employee (the abstact class itself, as opposed to its subclasses) objects.
    Employee[] employees = new Employee[20];
    employees[0] = new HourlyEmployee();That should work.
    So is it possible to create an array of Persons, cast
    either HourlyEmployees or SalariedEmployees into
    Employee objects, and then store the Employee objects
    in the Person array?You could do that as well, but you shouldn't need to cast it.
    Given the type hierarchy you describe, an HourlyEmployee is a Person, so you should be able to assign an HourlyEmployee directly to a Person-valued variable.
    And if I do that, can I still use
    methods particular to the SalariedEmployees and/or
    HourlyEmployees once they are in the Person array?No. If the method doesn't exist in Person, then you can't call it on a Person variable, even if the method does exist in the class implementing Person.
    But if the method exists in Person, but is implemented and possibly overridden in HourlyEmployee, you can still invoke it, by just invoking the Person method.
    public interface Person {
      public void feed();
    public abstract class Employee implements Person {
      public abstract void hire();
    public class HourlyEmployee extends Employee {
    // then:
    Person persons = new Person[20];
    // add HourlyEmployees or SalariedEmployees to persons array...
    persons[0].feed(); // OK!
    persons[0].hire(); // NOT OK!

Maybe you are looking for