Date: Fri, 21 Sep 2007 06:30:25 +0200 From: Pieter de Goeje <pieter@degoeje.nl> To: freebsd-questions@freebsd.org Subject: Re: Strange Java behaviour Message-ID: <200709210630.25709.pieter@degoeje.nl> In-Reply-To: <bef9a7920709201931x15cec9ddq21c080aca45d3de8@mail.gmail.com> References: <bef9a7920709201931x15cec9ddq21c080aca45d3de8@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Friday 21 September 2007, Aryeh Friedman wrote: > On every JDK (linux-sun-jdk14,jdk15,diablo-jdk15,linux-sun-jdk16 and > jdk16) I have tried this on it opens the JFrame then just dies > (immediatly): > > import javax.swing.JFrame; > > public class Main > { > public static void main(String[] args) > { > JFrame frame=new JFrame(); > > frame.pack(); > frame.setVisible(true); > > while(true) > ; > } > } > > I am using FreeBSD 7-Current with xorg 7.3 (gnome) Your code is wrong. You cannot do GUI creation / updating outside the Swing/AWT event dispatching thread. Also, the while(true); is unnessecary (and a waste of CPU time) because java does not terminate while there are active threads. For more information: http://java.sun.com/docs/books/tutorial/uiswing/concurrency/ Example: import javax.swing.*; public class Main { public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JFrame f = new JFrame("Hello"); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.setVisible(true); } }); } } Regards, Pieter de Goeje
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200709210630.25709.pieter>