Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #2169
| From | "IchBin" <ichbin@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: Swing thread problem |
| Message-ID | <dt2dnaZPNZTuVzPbnZ2dnUVZ_qKgnZ2d@comcast.com> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <1185817417.608675.37750@19g2000hsx.googlegroups.com> |
| Date | 2011-04-27 15:37 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui
Felix Dorner wrote:
> Hi,
>
> i am trying to write a small app that contains a few JFrames. The
> JFrame|s content is controlled by a small command line interpreter. My
> problem is, that the JFrames freeze. I created a small code sample to
> illustrate this (see below). I guess the Problem does not lie in the
> creation of the Swing elements but rather in the implementation of the
> Commandline Reader.
>
> Any help is welcome.
> Felix
>
> import javax.swing.JFrame;
> import javax.swing.SwingUtilities;
>
> public class MainClass {
>
> JFrame frame;
>
> public MainClass(){
> initGUI();
> runLoop();
> }
>
> public static void main(String[] args){
> new MainClass();
> }
>
> private void initGUI(){
> SwingUtilities.invokeLater(new Runnable(){
> public void run(){
> frame = new JFrame("Test");
> frame.setBounds(0,0,200,200);
> frame.setVisible(true);
> }
> });
> }
>
> private void runLoop(){
> BufferedReader in = new BufferedReader(new
> InputStreamReader(System.in));
> while(true){
> try {
> in.readLine();
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> }
>
> }
>
As Danial mentioned your code does work. You are just not doing anything
with the data your read from the BufferedReader.
Replace in.readLine with System.out.println(in.readLine()). You will
then see that you are reading the data. You are just not doing anything
with it once you read it. You should read into var or an array but not
sure what you are trying to do.
Maybe you could add say a visual swing object in to your JFrame and
write the output to that object. You need to explain what you are trying
to do.
These are the imports you should have presented with your example above:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
--
Thanks in Advance... http://weconsulting.org
IchBin, Philadelphia, Pa, USA http://ichbinquotations.weconsulting.org
______________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.gui | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Swing thread problem "Felix Dorner" <felix.dorner@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: Swing thread problem "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: Swing thread problem "IchBin" <ichbin@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: Swing thread problem "Felix Dorner" <felix.dorner@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: Swing thread problem "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
csiph-web