The Artima Developer Community
Sponsored Link

Java Answers Forum
HowTo: Display Labels after an Application is Loaded.

4 replies on 1 page. Most recent reply: Nov 11, 2005 12:04 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Collin Garymore

Posts: 22
Nickname: callan
Registered: Jan, 2005

HowTo: Display Labels after an Application is Loaded. Posted: Nov 5, 2005 4:04 AM
Reply to this message Reply
Advertisement

Hi everybody,
I wonder if someone can help me to solve this problem then.
1 - I'm mimicking a Keyboard (GUI application). When the Key "A" on a keyboard is pressed (for example),
the key ("A" in this example) on the GUI application "should" light up.
2 - The following code "should" have done so...but, I've got the first light up once, when starts the application.
3 - Then nothing for the following pressed keys (A to Z on the GUI).
Could someone tell me where I get it wrong, or suggest to me a simple way yet effective to do this, please?
Many thanks for your time.

...
 
/**
 *
 */
lightOn_A = new ImageIcon ( "ImagesKeys/lightOn_A.gif" );
label_A = new JLabel ( lightOn_A );
 
    if ( _keyPressed.equals ( "A" ) )
    {
        try {
            /**
             *
             */
            panel_LBD_Row2.removeAll ( );
 
            panel_LBD_Row2.add ( label_A );
            panel_LBD_Row2.add ( labelS );
            panel_LBD_Row2.add ( labelD );
            panel_LBD_Row2.add ( labelF );
            panel_LBD_Row2.add ( labelG );
            panel_LBD_Row2.add ( labelH );
            panel_LBD_Row2.add ( labelJ );
            panel_LBD_Row2.add ( labelK );
            panel_LBD_Row2.add ( labelL );
 
            panel_LBD_Row2.repaint ();
        }
        catch ( Exception ex ) { }
 
        panel_LBD_Row2.repaint ();
 
        try {
            javax.swing.SwingUtilities.invokeLater ( new Runnable ()
                {
                    public void run ()
                    {
                        panel_LBD_Row2.removeAll ( );
 
                        try {
                            Thread.sleep ( 1000 );
                        }
                        catch ( Exception ex ) { }
 
                        /**
                         *
                         */
                        panel_LBD_Row2.add ( labelA );
 
                        panel_LBD_Row2.add ( label_A );
                        panel_LBD_Row2.add ( labelS );
                        panel_LBD_Row2.add ( labelD );
                        panel_LBD_Row2.add ( labelF );
                        panel_LBD_Row2.add ( labelG );
                        panel_LBD_Row2.add ( labelH );
                        panel_LBD_Row2.add ( labelJ );
                        panel_LBD_Row2.add ( labelK );
                        panel_LBD_Row2.add ( labelL );
 
                        panel_LBD_Row2.repaint ();
                    }
                }
            );
        }
        catch ( Exception ex ) { }
    }
etc....


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: HowTo: Display Labels after an Application is Loaded. Posted: Nov 6, 2005 9:41 PM
Reply to this message Reply
...
 
/**
 *
 */
lightOn_A = new ImageIcon ( "ImagesKeys/lightOn_A.gif" );
label_A = new JLabel ( lightOn_A );
 
    if ( _keyPressed.equals ( "A" ) )
    {
        try {
            /**
             *
             */
            panel_LBD_Row2.removeAll ( );
 
            panel_LBD_Row2.add ( label_A );
            panel_LBD_Row2.add ( labelS );
            panel_LBD_Row2.add ( labelD );
            panel_LBD_Row2.add ( labelF );
            panel_LBD_Row2.add ( labelG );
            panel_LBD_Row2.add ( labelH );
            panel_LBD_Row2.add ( labelJ );
            panel_LBD_Row2.add ( labelK );
            panel_LBD_Row2.add ( labelL );
 
            panel_LBD_Row2.repaint ();
        }
        catch ( Exception ex ) { }
 
        panel_LBD_Row2.repaint ();
 
        try {
javax.swing.SwingUtilities.invokeLater ( new
eLater ( new Runnable ()
                {
                    public void run ()
                    {
                        panel_LBD_Row2.removeAll ( );
 
                        try {
                            Thread.sleep ( 1000 );
                        }
                        catch ( Exception ex ) { }
 
                        /**
                         *
                         */
                        panel_LBD_Row2.add ( labelA );
 
                        panel_LBD_Row2.add ( label_A );
                        panel_LBD_Row2.add ( labelS );
                        panel_LBD_Row2.add ( labelD );
                        panel_LBD_Row2.add ( labelF );
                        panel_LBD_Row2.add ( labelG );
                        panel_LBD_Row2.add ( labelH );
                        panel_LBD_Row2.add ( labelJ );
                        panel_LBD_Row2.add ( labelK );
                        panel_LBD_Row2.add ( labelL );
 
                        panel_LBD_Row2.repaint ();
                        
                        //  try include this here
                        panel_LBD_Row2.updateUI();
                        //  I assume panel_LBD_Row2 is a
                        //  JPanel
                    }
                }
            );
        }
        catch ( Exception ex ) { }
    }

Paul de Vrieze

Posts: 9
Nickname: pauldv
Registered: Oct, 2005

Re: HowTo: Display Labels after an Application is Loaded. Posted: Nov 7, 2005 1:29 AM
Reply to this message Reply
Shouldn't you call panel_LBD_Row2.validate() instead of panel_LBD_Row2.repaint ()?

Collin Garymore

Posts: 22
Nickname: callan
Registered: Jan, 2005

Re: HowTo: Display Labels after an Application is Loaded. Posted: Nov 10, 2005 7:22 AM
Reply to this message Reply
Hi spike,
I would like to thanks you for your time.
Your solution did work fine, amazing it could be...
For all others helps I did receive from Artima forums members, I would like to express my gratitude,
and hope that this community will stay alive for long to those like me craving to learn more from Sun's Java.
For all, many thanks.

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: HowTo: Display Labels after an Application is Loaded. Posted: Nov 11, 2005 12:04 AM
Reply to this message Reply
> Hi spike,
> I would like to thanks you for your time.
> Your solution did work fine, amazing it could be...
> For all others helps I did receive from Artima forums
> members, I would like to express my gratitude,
> and hope that this community will stay alive for long to
> those like me craving to learn more from Sun's Java.
> For all, many thanks.

No worries... I guess that's what this forum is for...
Sharing ideas and knowledge... I'm sure down the line
you'll help me solve some mind boggling stuff...

Good luck with the learning curve...

Flat View: This topic has 4 replies on 1 page
Topic: Applet Previous Topic   Next Topic Topic: Get current URL from Internet explorer

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use