The Artima Developer Community
Sponsored Link

Java Buzz Forum
SWT gives you the power of the infinite loop!

0 replies on 1 page.

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 0 replies on 1 page
Carlos Villela

Posts: 116
Nickname: cvillela
Registered: Jun, 2003

Carlos Villela is a Java developer working mostly with web technologies and AOP.
SWT gives you the power of the infinite loop! Posted: Jul 18, 2003 12:45 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Carlos Villela.
Original Post: SWT gives you the power of the infinite loop!
Feed Title: That's sooo '82!
Feed URL: http://www.jroller.com/rss/cv?catname=Technical
Feed Description: Carlos Villela's weblog. Everyday life, everyday software development, everyday musings.
Latest Java Buzz Posts
Latest Java Buzz Posts by Carlos Villela
Latest Posts From That's sooo '82!

Advertisement
I was just chatting with Umlauf tonight when I decided to ask him where he gets his SWT knowledge and references from. Despite the obvious ones, such as Google, the Eclipse website or the mailing lists and newsgroups, he pointed me to some cool links: one talking about the basic SWT widgets, and the Eclipse Wiki, which I hadn't visited before, and both worth a look if you're into GUI coding.

Browsing these sites a bit, I found one very interesting snippet:

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Main {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}

Pretty basic Hello World kind of example, but take a look at the while loop, dispatching all the events - some may argue this is absolutely awful, but I liked it a lot. If you think about this for a minute, you'll see that the SWT guys wanted to give us absolute freedom and visibility about how things are happening: if there needs to be a dispatcher loop somewhere, it better be on my own code than in the library, as it happens on Swing. Swing hides so much from you that debugging it is very hard, sometimes. To debug the event queue on SWT, all I need is to put a breakpoint inside readAndDispatch, and see what's happening. If I want to inject some events, to test my application, for instance, I only need to do it in one place. It's accessible, and I, just like everyone else, like accessible code, code that's easy to figure out.

Great. Maybe I even get excited to build GUI apps again :)

Read: SWT gives you the power of the infinite loop!

Topic: Make your process exclusively externally configurable Previous Topic   Next Topic Topic: JBoss AOP is lacking a decent join point model

Sponsored Links



Google
  Web Artima.com   

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