From owner-freebsd-questions@FreeBSD.ORG Fri Sep 21 04:30:40 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B422516A41A for ; Fri, 21 Sep 2007 04:30:40 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from smtp.utwente.nl (unknown [IPv6:2001:610:1908:1000:204:23ff:feb7:ef56]) by mx1.freebsd.org (Postfix) with ESMTP id 75E2C13C4B5 for ; Fri, 21 Sep 2007 04:30:36 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from lux.student.utwente.nl (lux.student.utwente.nl [130.89.170.81]) by smtp.utwente.nl (8.12.10/SuSE Linux 0.7) with ESMTP id l8L4UQxW028700 for ; Fri, 21 Sep 2007 06:30:26 +0200 From: Pieter de Goeje To: freebsd-questions@freebsd.org Date: Fri, 21 Sep 2007 06:30:25 +0200 User-Agent: KMail/1.9.7 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200709210630.25709.pieter@degoeje.nl> X-UTwente-MailScanner-Information: Scanned by MailScanner. Contact helpdesk@ITBE.utwente.nl for more information. X-UTwente-MailScanner: Found to be clean X-UTwente-MailScanner-From: pieter@degoeje.nl X-Spam-Status: No Subject: Re: Strange Java behaviour X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Sep 2007 04:30:40 -0000 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