Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2005

Tip: Looking for answers? Try searching our database.

problems migrating to AWT-EventQueue-0

Thread view: 
Wizumwalt@gmail.com - 29 Jun 2005 22:02 GMT
I'm trying to change my app to create the interface using only the
AWT-EventQueue-0 thread. My problem is that the thread cannot find the
class needed to initialize and I'm not sure how this would be done. I
really need to invoke all this w/ the AWT-EventQueue-0 thread as the
main thread instance was giving me problems.

: cannot find symbol
   [javac] symbol  : constructor Renderer(<anonymous
java.lang.Runnable>)
   [javac] location: class com.abc.Renderer
   [javac] listener = new Renderer(this);

--- code

public class MyTest extends JFrame implements ActionListener,
ItemListener, ChangeListener
{
    public Renderer listener = null;
    ...

    public MyTest() {
        Runnable runner = new Runnable() {
            public void run() {
                ...
                               // Isn't Renderer out of scope at this
point?
                               // How should this be handled?
                listener = new Renderer(this);
                canvas.addGLEventListener(listener);
                ...
            }
        }

        EventQueue.invokeLater(runner);
    }

    public static void main(String args[]) {
        MyTest window = new MyTest();
    }
}    

---

Any help much appreciated.
Knute Johnson - 29 Jun 2005 23:45 GMT
> I'm trying to change my app to create the interface using only the
> AWT-EventQueue-0 thread. My problem is that the thread cannot find the
[quoted text clipped - 40 lines]
>
> Any help much appreciated.

The way to do this is to create the GUI in a static method that you call
from main via EventQueue.invokeLater().

// pseudo code

class test {
    public static void createGUI() {
        // create gui here
    }

    public static void main(String[] args) {
        Runnable r = new Runnable() {
            public void run() {
                createGUI();
            }
        };
        EventQueue.invokeLater(r);
    }
}

Signature

Knute Johnson
email s/nospam/knute/

Wizumwalt@gmail.com - 30 Jun 2005 00:28 GMT
Unfortunately I have lots of non-static vars that I can't call from
another static class.

But what I did do was implement the Runnable interface to my main class
and it now has access to all my vars again.

Thnx
Knute Johnson - 30 Jun 2005 05:44 GMT
> Unfortunately I have lots of non-static vars that I can't call from
> another static class.
[quoted text clipped - 3 lines]
>
> Thnx

That's nice but your GUI won't be created in the EDT.  If your class has
some methods in it that you need, then instantiate it in the createGUI
method.  Then you have full access to them.  To follow the new
guidelines requires a complete rethinking of how your GUI and class will
function.

The other option is to just not worry about it and use the old method
unless it fails.

Signature

Knute Johnson
email s/nospam/knute/

Wizumwalt@gmail.com - 30 Jun 2005 15:33 GMT
Not sure I follow here ...

To see if I was creating these on the AWT-EventQueue-0 thread, I put
this funciton in my code and saw that by implementing the runnable
interface to my main class, I was creating everything from the
AWT-EventQueue-0 thread (everything meaning all my GUI methods showed
they were created from the AWT-EQ-0).

private static void print(String msg) {
  String name = Thread.currentThread().getName();
  System.out.println(name + ": " + msg);
}

And my main method just looks like this ...
MyClass win = new MyClass();
EventQueue.invokeLater(win);

What I have works now, but I want to make sure it's working correctly.
Knute Johnson - 01 Jul 2005 00:51 GMT
> Not sure I follow here ...
>
[quoted text clipped - 14 lines]
>
> What I have works now, but I want to make sure it's working correctly.

If MyClass is where you create your GUI, that is not being created in
the EDT.  What you show me is that the thread of your class MyClass is
running in the EDT.  That may not be what you really want.  See this
article:

http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html

Signature

Knute Johnson
email s/nospam/knute/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.