Extending component class

Just recently wrote a diary applet that includes all twelve months of the year and thier corresponding days in month panels. The user can cylcle through each year and the panels change accordingly. User can also select and de-select days of the week in any month using left and right mouse clicks respectivley.
The individual months are painted to a Panel object and I use mouselisteners to determine x,y co-ordinates of the pointer to determine which days to colour as selected.
However yesterday I was given a new spec that requires each day selected to "remember" its color, year, month, location and was advised to create each individual day in my own class extending Component, not to use MouseEvents but Action events instead (did I mention I'm restricted to using Java 1.1!).
Could anyone explain what needs to be done to produce a months worth of days as a calendar using a class that extends Component. Cheers.

Each of your days is essentially a toggle/radio button, they can be selected and deselected. Ignore what they look like for now - it's the functionality that's important.
Each day component is responsible for determining whether it's been clicked or not.
Your month panel is then simply a grid of these (perhaps with headers etc.).
Your year display is just a card layout (or tabbed pane or whatever) of various month panels.
Here's an example of how to code up a simple day component:
public class DayComponent extends Component implements MouseListener
  // The date that this component represents
  // Could actually be a Date but we'll keep it simple for now
  private int day;
  // Whether this day is selected
  private boolean selected;
  public DayComponent(int day)
    this.day = day;
    selected = false;
    // This component listens for mouse events over itself
    addMouseListener(this);
  public void setSelected(boolean selected)
    this.selected = selected;
    repaint(); // Causes this component to update its background
  public boolean isSelected()
    return selected;
  public Dimension getPreferredSize()
    return new Dimension(20, 20); // Or something
  public void paint(Graphics g)
    g.setColor(selected?Color.lightGray:Color.yellow); // For example
    g.fillRect(0, 0, getSize().width, getSize().height);
    g.setColor(Color.black);
    g.drawString(String.valueOf(day), 10, 10); // Work out the position properly...
  public void mouseEntered(MouseEvent e)
  public void mouseExired(MouseEvent e)
  public void mousePressed(MouseEvent e)
  public void mouseReleased(MouseEvent e)
  public void mouseClicked(MouseEvent e)
    // Toggle the selection state of this button when the mouse is clicked
    setSelected(!selected);
}That's really all there is to it. Storing the state of the buttons to the hard drive or somewhere else is a different matter.
If you think about what this is doing, it's basically just a radio button so you might find it neater to actually extend something like Button, JButton, JToggleButton etc. to get even more advanced behaviour. This is certainly worth doing eventually since you'll want to avoid writing layout and painting code if you can help it ('cos it can get messy).
Hope this helps.

Similar Messages

  • Implementation of DragManager in extended Panel class

    Hi,
    I'm facing a problem during implementation of DragManager in
    extended Panel class. I've a component which is extending the Panel
    class where I've attached four Images with their corresponding
    dragging features.
    Say, the four images' x positions as these: x1 = 10, x2 = 20,
    x3 = 30, x4 = 40. After adding the DragManger class and
    implementation of dragging feature to those Images, the dragging is
    works fine. But, the problem is, when I'm dragging x1 image, the
    imageProxy associated to x1 starts showing from exactly the x1
    position, but also all the three images' (x2, x3, x4) imageProxy
    starts dragging from x1 position only! When the expected result is,
    the x2 imageProxy shud starts drag from x2 x position itself, and
    for other x3 imageProxy from x3 position and x4 is their also.
    Except the x1 image, all the other three's imageProxy are not
    starts from their respective image x position.
    Anyone can give any idea.. how to overcome this?
    tnks.
    ASB

    What are the:
    DragManager.doDrag(initiator, ds, event, imageProxy, x, y,
    1.0);
    x and y parameters in your drag manager's doDrag method? They
    should be calculated from the point of mouse click that would
    event.localX and event.localY.
    ATTA

  • Cannot load component class className from project: ProjectName

    Hi guys,
    I've a strange issue.
    I found some solutions on google and on this forum, but they doesn't work for me.
    I've a javafx application in netbeans in which I also use swing controls.
    I created a custom jlabel control
    public class Label extends JLabel {
        public Label()
        private void setAspect(String csFontName, int nSizeFont, boolean bold,Color cColor)
            int style=bold ? Font.BOLD : Font.PLAIN;
            this.setFont(new Font(csFontName,style,nSizeFont));
            this.setForeground(cColor);
        public Label(String csText)
            super(csText);
            setAspect("Tahoma",10,false,Color.black);
        public Label(String csText, int nSize)
            super(csText);
            setAspect("Tahoma",nSize,false,Color.black);
        public Label(String csText, int nSize, boolean bold)
            super(csText);
            setAspect("Tahoma",10,bold,Color.black);
        public Label(String csText, int nSize, boolean bold, Color cColor)
            super(csText);
            setAspect("Tahoma",10,bold,Color.black);
    }I selected Label.java file in the project and I click on Tools->add to palette and I selected Swing controls as family.
    I restarted netbeans and I found it in the palette.
    I try to drag it into my swing form and I've :
    Cannot load component class <ProjectName>.Label from project: D:\Progetti\<ProjectName>.
    The class must be compiled and must be on the classpath of the project to which this form belongs.Following forums I went on netbeans log
    org.openide.ErrorManager$AnnException: msg
         at org.openide.ErrorManager$AnnException.findOrCreate(ErrorManager.java:870)
         at org.openide.ErrorManager$DelegatingErrorManager.annotate(ErrorManager.java:653)
    Caused by: java.lang.ClassNotFoundException: <ProjectName>.Label
         at org.netbeans.modules.form.project.ProjectClassLoader.findClass(ProjectClassLoader.java:178)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
         at org.netbeans.modules.form.project.FormClassLoader.findClass(FormClassLoader.java:83)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:247)
         at org.netbeans.modules.form.project.ClassPathUtils.loadClass(ClassPathUtils.java:98)
         at org.netbeans.modules.form.MetaComponentCreator.prepareClass0(MetaComponentCreator.java:1322)
         ... 34 more
    msg
    Cannot load component class ortholab2.Label from project: D:\Progetti\<ProjectName>.
    The class must be compiled and must be on the classpath of the project to which this form belongs.I hope someone can help me ,
    Thanks

    That sounds more like a NetBeans-specific question, not a general java programming question.
    Plus, your desciption is inconsistent:
    Cannot load component class <ProjectName>.Label from project: D:\Progetti\<ProjectName>.
    Cannot load component class ortholab2.Label from project: D:\Progetti\<ProjectName>What is the fully-qualified name of this class: ortholab2.Label ? ortholab2 being both the package name and the project name?
    And where do you use it, in the same project or in yet another NetBeans project?

  • The Component class

    Can anybody tell me why the Component class should be an abstract class? It seems to me that the class should be defined as a concrete class because non of its methods is abstract type. Thanks. altech

    Most likely it was done so that developers seeking to create a new flavor of AWT Component would be required to extend the Component class, rather than creating generic Components left and right. A generic Component object isn't really useful at all anyway, due to its lack of interesting behavior.
    The class is intended to act as an interface for users of Component subclasses (not interface as in a Java interface, but in the general OO sense of the word). It is a common root for all AWT "components," so that they may be acted upon in a similar fashion utilizing polymorphism.
    There may be a more legitimate reason why it is abstract, but this is my guess. It makes sense to me.

  • ?Is it possible to create a javafx class without extending Application class ? If yes, how

    Is it possible to create a javafx class without extending Application class ? If yes, how ?

      There is no  such thing as a javafx  class.  It is a regular  java class.  The Aapplication class is  the entry
    point  for JavaFX application.  You have to extend the Application class to create Javafx  application .

  • LoadClass    (error loading a class which extends other class  at run-time)

    Hey!
    I'm using the Reflection API
    I load a class called 'SubClass' which exists in a directory called 'subdir' at run-time from my program
    CustomClassLoader loader = new CustomClassLoader();
    Class classRef = loader.loadClass("SubClass");
    class CustomClassLoader extends ClassLoader. I have defined 'findClass(String className)' method in CustomClassLoader.
    This is what 'findClass(String className)' returns:
    defineClass (className,byteArray,0,byteArray.length);
    'byteArray' is of type byte[] and has the contents of subdir/SubClass.
    the problem:
    The program runs fine if SubClass does not extend any class.
    If however, SubClass extends another class, the program throws a NoClassDefFoundError. How is it conceptually different?
    Help appreciated in Advance..
    Thanks!

    Because i'm a newbie to the Reflection thing, i'm notI don't see reflection anywhere. All I see is class loading.
    sure what role does the superclass play when i'm
    trying to load the derived class and how to get away
    with the errorWell... hint: all the superclass's stuff is not copied into the subclass.
    I am quite sure it fails to load the superclass because of classpath issues.

  • Error while extending controller: class name is wrong or not included

    Hi All,
    I am getting this error while I port my extended controller class to the custom top and assign this controller to the page. I have made sure its the class file that is copied. The directory is correct, the permissions were given using chmod 775. There exists a soft link betwen the custom top and the oracle top as well. What else am I missing here?
    Error: oracle.apps.fnd.framework.OAException: Could not create Java class: (oracle.apps.ap.oie.entry.webui.XXEntryFlowPageCO) associated with region: (GeneralInformationPG). This is probably because the class name is wrong or not included in project.

    :( Started out with that Gyan. If i do give the path with xx. appended to it, it lets me save and when i log back in and there are no changes to the page. I go to the personalise option to find the modification has been overwritten. I was told that this is so because Oracle doesnt recognise the xx.path and since there exists a soft link already the standard path with the new controller name should work.
    i have really tried both of these options and am not sure what could be wrong. thanks for all your attempts to help. anything else i can try?

  • Loading external swfs extending from classes in the same shared codebase

    Hey there!
    I'm currently developing a game in flash and want to be able to divide up my .fla assets in a way that means artists can work on a game menu .fla in isolation from the game.fla and rest of the game code.
    If I could briefly explain how I've approached this so far, I would be extremely if people could shout in my general direction and tell me I am stupid, or even better still, give me helpful advice as to where I am going wrong and how I can correct it!
    My project is setup like this:
    HighScoreMenu.fla -> document class HighScoreMenu extending GameMenu class.
    game.fla ->document class game.as
    game.as class loads the published HighScoreMenu.swf and manipulates the menu i.e. animates on and off screen via inherited functions in the GameMenu class.
    Now this seemed to work to begin with, until my code evolved and upon going to publish my HighScoreMenu.fla flash started complaining about symbols being used in Game.as that were in Game.fla...  If I'm only publishing the HighScoreMenu which extends from GameMenu then why is it even looking to compile Game.as?
    Can you spot the problem in the way I am doing this, or is there a better approach I should try?
    Any advice greatly appreciated!
    Stevie.

    No it doesn't seem to, however though they both have a reference to the HighScoreManager so there is some overlap there between menu and game code, but the menu classes don't reference any symbols on the game.fla...
    Just to clarify, I have an fla HighScoreMenu.fla, which has a child symbol HighScoreMenu which uses the following class.
    public dynamic class HighScoreMenu extends GameMenu
         //convenient storage for competition Manager object
         private var _highScoreManager:HighScoreManager;
    The game then loads this class as follows:
    I load the swf "HighScoreMenu.swf" and once its loaded I obtain the menu class like so:
    var cls:Class = Class( applicationDomain.getDefinition("Menus.HighScoreMenu") );
    var object:* = new cls();
    ...and create a new instance of the menu.
    Is there anything fundamentally wrong with approaching it in this way?

  • Not able to pass values to variables in extended Tree class

    Hi,
    I have a as class that extends from Tree, additionally this
    custom class defines
    new class level variables as follows:
    public class MyTree extends Tree {
    public var arrayColl:ArrayCollection;
    and i call this tree from mxml as follows:
    <customTree:MyTree
    arrayColl={list}
    xmlns:customTree="../../.*"/>
    Though my 'list' collections is not null, when i place an
    alert in the constructor of extended tree class
    it shows as null.
    Please advice.
    Thanks,
    Lucky

    below is the canvas:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="
    http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[
    import mx.collections.IViewCursor;
    import mx.collections.ArrayCollection;
    import com.citi.ascript.TreeData;
    import mx.controls.Alert;
    import com.citi.ascript.CitiTree;
    public var availableTreeDataColl:ArrayCollection;
    public var selectedTreeDataColl:ArrayCollection;
    public var treeData:TreeData;
    public var srcTree:CitiTree;
    public var availableTreeDataArray:Array = [{a:1},
    {b:2},
    {c:3}
    public function formTreeData():void {
    var tempColl:ArrayCollection = new
    ArrayCollection(availableTreeDataArray);
    availableTreeDataColl = new ArrayCollection();
    for (var i:int=0; i<tempColl.length; i++) {
    var tempTreeData:Object = tempColl
    treeData = new TreeData();
    treeData.a = tempTreeData.a;
    treeData.b = tempTreeData.b;
    treeData.c = tempTreeData.c;
    availableTreeDataColl.addItem(treeData);
    ]]>
    </mx:Script>
    <mx:VBox>
    <mx:Label text="Drag &amp; Drop the analysis sections
    that you would like to include in the report" width="450"
    height="20"/>
    <mx:HBox id="treeContainer"
    creationComplete="formTreeData();">
    <customTree:MyTree treeList={availableTreeDataColl} //
    here collection becomes null.
    </customTree:MyTree>
    </mx:HBox>
    </mx:VBox>
    </mx:Canvas>
    The collection of TreeData is iterated in the customTree to
    form xml which will act as dataprovider for tree.
    and this canvas is added as a child for a panel in my main
    application.
    Hope this gives an idea.
    Thanks,
    Lucky

  • How to map a custom enum list to a custom form property in an extended incident class

    Hi,
    I'm struggeling to understand how to map a custom enum list to a custom form property in an extended incident class.
    Here's what i want to have happen:
    I am going to publish a request offering on my SMPortal for allowing users to submit basic IT incidents. I want the form to include "Whom does this problem affect" (answers(This is the custom enum list): Me, Multiple Users, Whole department or Whole
    company), "What is the problem about", "Description" and "Attachments".
    Here's what i've done:
    In the authoring tool i created a MP for the custom enum list and put only the list in it. I sealed the MP and imported it.
    I created another unsealed MP called TST.Incident.Library for storing incident library customizations and extended the incident class to add an extension class i called ClassExtension_Affected scope with a custom property i called AffectedScope. Then i am trying
    to set the datatype of this property to "list". In the "select a list" dialog i cannot chose my previously sealed MP with the custom enum list in it. Why?
    - Do i need to scratch the sealed MP and put the custom enum list in the latter TST.Incident.Library MP instead?
    - If so, can i do that and keep this MP unsealed, or will i get an error on import saying "Unsealed management packs should not contain type definitions"
    - Should i create one sealed MP for both the custom enum list and the extension class + custom property?

    Hi,
    Authoring Tool simply isn't informed about your list. Open the sealed management pack where you define the root of the list in the Authoring Tool and in the same time open TST.Incident.Library. You will have two opened MPs in the Authoring
    Tool and be able to add a custom list for your custom field.
    Cheers,
    Marat
    Site: www.scutils.com  Twitter:
      LinkedIn:
      Facebook:

  • Abstract class extends other class?

    What happens when a abstract class extends other class?
    How can we use the abstract class late in other class?
    Why do we need an abstract class that extends other class?
    for example:-
    public abstract class ABC extends EFG {
    public class EFG{
    private String name="";
    private int rollno="";
    private void setName(int name)
    this.name=name;
    private String getName()
    return this.name;
    }

    shafiur wrote:
    What happens when a abstract class extends other class?Nothing special. You have defined an abstract class.
    How can we use the abstract class late in other class?Define "Late". What "other class"?
    Why do we need an abstract class that extends other class?Because it can be useful to define one.

  • How to extend a class in same package

    I have a class called LoginBean.java which extends the class ConnectDB.java
    this both files have a statement both the classes are under the directory pmtools.
    and both are included in package pmtools.
    (they both have statement "package pmtools; " at top)
    when i am trying to compile LoginBean.java, it is giving me following error,
    LoginBean.java:7: cannot resolve symbol
    symbol : class ConnectDB
    location: class pmtools.LoginBean
    public class LoginBean extends ConnectDB
    ^
    LoginBean.java:59: cannot resolve symbol
    symbol : variable dbConn
    location: class pmtools.LoginBean
    stmt = dbConn.createStatement();
    ^
    2 errors

    did you compile the other class already? donnow if ithahahaha!!!!!
    ok include the import statement
    import pmtools.ConnectDB;
    in the second class and than compile..

  • Extend base class to customize some properties

    Hi
    Using Jdev 11g
    I need to extend UIGraph class to change the defualt color of pie graph . anyone have a solution to it ? i already extend the class but i donot know what is next steps and what is the method i must to override ??

    Hi frank
    how can i use skinning to change default color of pie chart . for example i have 5 status and count them for every emp but i need specified color for every status ( green for done , red for not done ans so on) if one status missing ( the emp have not (,done status) for example) then the pie color rearranged for other status ???:)). i try to change color in EL but color attr of pie series donot support EL

  • How to Extend Java class in UI Module

    Hi All,
    I am trying to make z for one of the java file GenericSearchDynamicContent.java in the standard package com.sap.wec.app.common.module.catalog.ui.utils. Can anyone please let me know what are steps do i need to follow to extend the same java file in our customer namespace and make use of it.
    Thanks in Advance.
    Regards,
    Rahul.

    Hi Rahul,
    It's upto you whether you want to keep seprate packages for custom changes (then create your own package and keep all the Z class under this) or create a Z_GenericSearchDynamicContent.java and extend this class by GenericSearchDynamicContent.java.
    After doing this you can make your custom changes accordingly and you have to also make the changes in *config.xml (replace this entry GenericSearchDynamicContent by Z_GenericSearchDynamicContent.java.) files as mapping is done there.
    Could you please let me know if you need any further information.
    Thanks,
    Hamendra

  • Error  "expected a myfaces custom component class in package"

    Can anybody help me on this?
    just copied the sandbox code on selectmanypicklist and tried in a separate package of mine.
    created a jsp page and used the selectmanypicklist component and im getting the component on my browser.
    But whn i added the javascript resource calling by "encodeJavascript(facesContext, uiComponent);" im geting an error saying tht "expected a myfaces custom component class in package org.apache.myfaces.custom". i placed the java script file in "mypackage/list/resource/pikscript.js".
    should i add anything on faces-config.xml file or anywhr else?
    Anybody can help on this?
    Thanx in Advance.

    The problem is that it calls a method validateCustomComponent in MyFacesResourceHandler to see if it can load the js file. This method controlls if the path of the js file begins with org.apache.myfaces.custom. If not throws an exception and doesn't load the file. I changed the package of the class that's trying to load the file in org.apache.myfaces.custom.xx and the package of the file js in org.apache.myfaces.custom.xx.resource. Now it's working.

Maybe you are looking for

  • Is there a maximum song length for the iPhone?

    I have an audio bible that works fine in iTunes, my 20GB & 30GB iPods. However it will not play on my iPhone.

  • Publishing a Garageband Podcast to another webserver (not MobileMe)

    Hi all, Got a dilemma here that I'm sure some other people must have come across. I have a friend who has been publishing a podcast site for a few years using Garageband > iWeb > Me.com hosting (so iWeb is uploading all of the files, and creating the

  • Alv grid error

    hi all, I have simple issue in alv grid, I have designed an alv grid, by default it has scroll bars. when i scroll the alv grid, the last executed status message (ie in pai) is executed on every page and the message shows in the status bar on every s

  • How findout who created a software component:

    I am in a situation where I have to findout which user (userid) created a software component in SLD and imported them into IR and created many namespaces? Is there a way to find out? Regards, N.S

  • Safari Random Quit -- any solutions yet?

    Safari 6 on 10.7 Lion has been randomly quitting on me for months now. There is no error report just this message in the Console: Received an invalid message from the web process with message ID 323002f I see that others are having the same problem w