How can you get  the public variables from object that extends JLabel?

I'm using the mouseClickedListener method e.getComponent(); to get the component that is clicked on the sceen. The component i clicked is type "object" and extends a jlabel, and i really need to acces a variable from it. Heres the code i'm using-
MouseListener listenerDown=new java.awt.event.MouseListener() {
        public void mousePressed(MouseEvent e){
            paintAll();
            mX=e.getX();
            mY=e.getY();
        public void mouseClicked(MouseEvent e) {
            Component c = e.getComponent();
            drawResizeBox(c);
            selected=c;
        public void mouseReleased(MouseEvent e) {
        public void mouseEntered(MouseEvent e) {
        public void mouseExited(MouseEvent e) {
package javapoint;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.Line2D;
import java.awt.image.BufferedImage;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
public class object extends JLabel{
    public object(Rectangle rect,int id){
        idNum=id;
        Rect=rect;
        BufferedImage image = new BufferedImage((int)rect.getWidth()+1, (int)rect.getHeight()+1, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = (Graphics2D) image.getGraphics();       
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.drawRect((int)rect.getX(), (int)rect.getY(), (int)rect.getWidth(), (int)rect.getHeight());
        Icon icon = new ImageIcon((Image)image);
        setIcon(icon);
        setBounds((int)rect.getX()-1, (int)rect.getY()-1, (int)rect.getWidth()+1, (int)rect.getHeight()+1);
        mainFrame.slideArr[mainFrame.sIndx].add(this);
        setVisible(true);
        r=true;       
    object(Oval oval,int id){
        idNum=id;       
        setBounds(oval.getX(), oval.getY(), oval.getWidth(), oval.getHeight());
        getGraphics().drawOval(oval.getX(), oval.getY(), oval.getWidth(), oval.getHeight());
        o=true;
        setVisible(true);
    object(Line2D line,int id){
        idNum=id;       
        setBounds((int)line.getX1(), (int)line.getY1(), (int)line.getX2(), (int)line.getY2()); //Not gunna work
        getGraphics().drawLine((int)line.getX1(), (int)line.getY1(), (int)line.getX2(), (int)line.getY2());
        l=true;
        setVisible(true);
    object(Icon icon,int id){
        idNum=id;
        setIcon(icon);
        setBounds(50,50,icon.getIconWidth(),icon.getIconHeight());
        i=true;
        setVisible(true);
    void drawObject(object obj){
        if(r){
            Rectangle rect=obj.Rect;
            setBounds((int)rect.getX()-1, (int)rect.getY()-1, (int)rect.getWidth()+1, (int)rect.getHeight()+1);          
            Rect=rect;
            BufferedImage image = new BufferedImage((int)rect.getWidth()+1, (int)rect.getHeight()+1, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g = (Graphics2D) image.getGraphics();           
            g.setColor(Color.red);
            g.drawRect(0, 0, (int)rect.getWidth(), (int)rect.getHeight());           
            Icon icon = new ImageIcon((Image)image);
            setIcon(icon);
        }else if(l){
        }else if(o){
        }else if(i){
    public boolean r=false;
    public Rectangle Rect;
    public boolean o=false;
    public Oval Oval;
    public boolean l=false;
    public Line2D Line;
    public boolean i=false;
    public Icon Icon;
    public JLabel label;
    public int idNum;
}Edited by: ghostbust555 on Feb 12, 2010 2:14 PM

ghostbust555 wrote:
Well see the problem is i have an array of 200 objects.What does that have to do with anything? And if it does, why isn't it in the code you posted?
I dont understand what you mean in your "Edit..." part. could you show some code/ explain farther? sorry if its a dumb question I'm still a bit of a novice at java.Yeah.
object yuck = (object) e.getComponent(); // That's a cast.
boolean yucksR = yuck.r; // Get the "r" variable from the object.

Similar Messages

  • How can I get the "text" field from the actionEvent.getSource() ?

    I have some sample code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.ArrayList;
    public class JFrameTester{
         public static void main( String[] args ) {
              JFrame f = new JFrame("JFrame");
              f.setSize( 500, 500 );
              ArrayList < JButton > buttonsArr = new ArrayList < JButton > ();
              buttonsArr.add( new JButton( "first" ) );
              buttonsArr.add( new JButton( "second" ) );
              buttonsArr.add( new JButton( "third" ) );
              MyListener myListener = new MyListener();
              ( (JButton) buttonsArr.get( 0 ) ).addActionListener( myListener );
              ( (JButton) buttonsArr.get( 1 ) ).addActionListener( myListener );
              ( (JButton) buttonsArr.get( 2 ) ).addActionListener( myListener );
              JPanel panel = new JPanel();
              panel.add( buttonsArr.get( 0 ) );
              panel.add( buttonsArr.get( 1 ) );
              panel.add( buttonsArr.get( 2 ) );
              f.getContentPane().add( BorderLayout.CENTER, panel );
              f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              f.setVisible( true );
         public static class MyListener  implements ActionListener{
              public MyListener() {}
              public void actionPerformed( ActionEvent e ) {
                   System.out.println( "hi!! " + e.getSource() );
                   // I need to know a title of the button (which was clicked)...
    }The output of the code is something like this:
    hi! javax.swing.JButton[,140,5,60x25,alignmentX=0.0,alignmentY=0.5,
    border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@1ebcda2d,
    flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,
    disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=14,bottom=2,
    right=14],paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=true,
    rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=first,defaultCapable=true]
    I need this: "first" (from this part: "text=first" of the output above).
    Does anyone know how can I get the "text" field from the e.getSource() ?

    System.out.println( "hi!! " + ( (JButton) e.getSource() ).getText() );I think the problem is solved..If your need is to know the text of the button, yes.
    In a real-world application, no.
    In a RW application, a typical need is merely to know the "logical role" of the button (i.e., the button that validates the form, regardless of whether its text is "OK" or "Save", "Go",...). Text tends to vary much more than the structure of the UI over time.
    In this case you can get the source's name (+getName()+), which will be the name that you've set to the button at UI construction time. Or you can compare the source for equality with either button ( +if evt.getSource()==okButton) {...}+ ).
    All in all, I think the best solution is: don't use the same ActionListener for more than one action (+i.e.+ don't add the same ActionListener to all your buttons, which leads to a big if-then-else series in your actionPerformed() ).
    Eventually, if you're listening to a single button's actions, whose text change over time (e.g. "pause"/"resume" in a VCR bar), I still think it's a bad idea to rely on the text of the button - instead, this text corresponds to a logical state (resp. playing/paused), it is more maintainable to base your logic on the state - which is more resilient to the evolutions of the UI (e.g. if you happen to use 2 toggle buttons instead of one single play/pause button).

  • How can i get the all values from the Property file to Hashtable?

    how can i get the all values from the Property file to Hashtable?
    ok,consider my property file name is pro.PROPERTIES
    and it contain
    8326=sun developer
    4306=sun java developer
    3943=java developer
    how can i get the all keys & values from the pro.PROPERTIES to hashtable
    plz help guys..............

    The Properties class is already a subclass of Hashtable. So if you have a Properties object, you already have a Hashtable. So all you need to do is the first part of that:Properties props = new Properties();
    InputStream is = new FileInputStream("tivoli.properties");
    props.load(is);

  • How can i get the max rpm from cpu fan??

    how can i get the max rpm from my cpu cooler regarding that i don't have a speed controller attached to the cpu fan ,,, ??  please make things clear for me
    thanks

    if you have not reduced it by using a speed controller either hardware or software or by the 7v mod its already going as fast as it will at 12 v dc you cannot speed it up only slow it down
    need more air get a different cooler/fan

  • How can I get the edited pictures from the thumbnails to full size?

    I upgraded to iPhoto 11, the thumbnail photos show my previous edits, but when I click on the photo to make it bigger, it reverts back to the unedited, original picture.  How can I get the edited pictures from the thumbnails to full size?

    Verify you are using iPhoto11 ver 9.5
    if not run the >Software update or check your apps folder and make sure the correct iPhoto is launched,  not an older ver.

  • How can I get the XML structure from a flat structure?

    Hi all,
    in my XI SP 12 I use a JMS adapter to read information using the WebSphereMQ transport protocol.
    The structure that I receive have this format:
    <Name_A.KeyFieldValue><Name_A.fieldName_A1_Value>...<Name_A.fieldName_AN_Value>
    <NumberRecordType_B><NumberRecordType_c>
    <Name_B.KeyFieldValue><Name_B.fieldName_B1_Value>...<Name_B.fieldName_BN_Value>
    <Name_B.KeyFieldValue><Name_B.fieldName_B1_Value>...<Name_B.fieldName_BN_Value>
    <Name_C.KeyFieldValue><Name_C.fieldName_C1_Value>...<Name_C.fieldName_CN_Value>
    <Name_C.KeyFieldValue><Name_C.fieldName_C1_Value>...<Name_C.fieldName_CN_Value>
    the problem is that in this structure each line is not separated by a carriage return or a comma, I have all the information in a single line:
    <Name_A.KeyFieldValue><Name_A.fieldName_A1_Value>...<Name_A.fieldName_AN_Value><NumberRecordType_B><NumberRecordType_c><Name_B.KeyFieldValue><Name_B.fieldName_B1_Value>...<Name_B.fieldName_BN_Value>...<Name_B.KeyFieldValue><Name_B.fieldName_B1_Value>...<Name_B.fieldName_BN_Value><Name_C.KeyFieldValue><Name_C.fieldName_C1_Value>...<Name_C.fieldName_CN_Value>...<Name_C.KeyFieldValue><Name_C.fieldName_C1_Value>...<Name_C.fieldName_CN_Value>
    and the customer don't want to insert a line separator.
    Then, the question is:
    How can I get the XML structure from this structure?
    If possible, I don't want to develop new Module and add it in the JMS Module Sequence.
    PS I have already read the article "How to Use the Content Conversion Module with the XI 3 J2EE JMS Adapter.pdf" and it doesn't seem to help me.
    Best Regards,
    Paolo

    To get context parameters from your web.xml file you can simply get the ActionServlet object from an implementing action object class. In the perform (or execute) method make the following call.
    ServletContext context = getServlet().getServletContext();
    String tempContextVar =
    context.getInitParameter("<your context param >");

  • How can i get the source code from java concurrent program in R12

    Hi 2 all,
    How can i get the source code from java concurrent program in R12? like , "AP Turnover Report" is java concurrent program, i need to get its source code to know its logic. how can i get its source code not the XML template?
    Regards,
    Zulqarnain

    user570667 wrote:
    Hi 2 all,
    How can i get the source code from java concurrent program in R12? like , "AP Turnover Report" is java concurrent program, i need to get its source code to know its logic. how can i get its source code not the XML template?
    Regards,
    ZulqarnainDid you see old threads for similar topic/discussion? -- https://forums.oracle.com/forums/search.jspa?threadID=&q=Java+AND+Concurrent+AND+Source+AND+Code&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Thanks,
    Hussein

  • How can you get the keypad on a USB keyboard to work in Excel

    How can you get the keypad on a USB keyboard to work in Excel for Mac.  Mouse keys is disabled/unchecked, but cannot get it to work.  Even tried downloading a 'num lock' app and it didn't help.

    Hi Michael-
    I do not have any problem with using shift registers in timed loops.  What version of LabVIEW are you using?  Can you please elaborate on why neither shift registers or local variables meet your needs?  I have attached a VI that saves a previous iteration and then computes and displays the difference.  Let me know if you have problems running it.
    Thanks-
    Tom W
    National Instruments
    Attachments:
    TimedLoop_ShiftReg.vi ‏74 KB

  • How can you get the schedule of a single reoccurring job with Restart ability in Redwood to pause when it has failed...?

    We need the Request Restart ability when scheduling a single reoccurring job in Redwood. Most of our jobs are scheduled in CHAINs which offers the Final Status Handler on Step level, and the schedule is "paused" when a job in the CHAIN has failed ( the next instance does not populate until the OP MSG has been Replied to) , and once the OPERATOR message is replied to, the CHAIN can resume running again ( desired ) . But we need this same ability when scheduling a single job not in a CHAIN. In our testing, we set up a job with Request Restart chosen on the Error , Killed and Unknown selections on the Restart Behavior Tab. But we found when a job is scheduled say once a day at 8AM, and when it fails, an OPERATOR msg appears allowing a Restart choice ( desired), but the next day's schedule also populates ( undesired) and we do NOT want the schedule to continue on yet because we need a chance to fix the error before the next insance runs for business reasons. So how can you get the schedule of a single reoccurring job with Restart ability in Redwood to pause when it has failed...?

    Hello Fran,
    You can wrap the job chain in a master job chain in the first step and set the final status handler there.
    You can also set the Restart Behavior to 'Stop Submit Frame', in that case you will have to resubmit the job once you are finished troubleshooting.
    Regards Gerben

  • How can I get the data back from my game

    How can I get the data back from minecraft if I deleted the app and bought with a different Apple ID

    No, they are tied to the ID that purchased them, and cannot be transferred to anyone else.

  • How can you get the apple tv to work in a hotel where to get on the wifi you have to still go to a website first and put in your room

    How can you get the apple tv to work in a hotel where to get on the wifi you have to still go to a website first and put in your room?

    Welcome to the Apple Community.
    Unfortunately the Apple TV doesn't have a web browser so you can't do that.

  • How can you get the filter off if you can't remember the password? It's"pro con" and it wont even let me check out the rates for aflight.

    How can you get the filter off if you can't remember the password? It's"pro con" and it wont even let me check out the rates for aflight.

    You can check the file prefs.js in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder] and remove the line(s) related to that extension (procon.password).

  • I accidentally erased a music album that I purchased on iTunes. How can I get the iTunes store to recognize that it is no longer in my iTunes library and download it again?

    I accidentally erased a music album that I purchased on iTunes. How can I get the iTunes store to recognize that it is no longer in my iTunes library and download it again?

    Delete the broken links in iTunes then look at your purchased list to redownload.
    If this happened because you were deleting files from the iTunes folder in Finder, don't.  You have to let iTunes do all the deleting and moving or you will end up with broken links.

  • How can I get the amount of free space that is on my drive to show at the bottom of the drive in Lion.

    How can I get the amount of free space that is on my drive to show at the bottom of the drive in Lion.
    This is a must feature for me and I may have to go back to Snow Leopard.
    Please help!

    Right click on your desktop and choose "viewer options". Adjust the spacing and the size of your icons and you should be able to see the size of your drive(s) and the free space available on each drive with the exception of your bootcamp drive which will only show the overall size of the drive you have it on.  This may be different if you only have one system drive (like on a Mac Book Pro) with a partition containing bootcamp on it. this may only show you the overall capacity, I can't say for sure though as I only use a Mac Pro with 4 seperate Hard Drives which are showing both overall capacity and free space available. Hope this helps
    Denisimo

  • How can I get the ip addres of computers that log into my Applet?

    How can I get the ip addres of computers that log into my Applet?
    Thanks
    REuven

    Try using method getAddress of class InetAddress.

Maybe you are looking for