aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Direction needed on how to harness my run-away program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Direction needed on how to harness my run-away program" Watch "Direction needed on how to harness my run-away program" New topic
Author

Direction needed on how to harness my run-away program

Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
Hello,

I have an assignment to implement a few text searching algorithms. I've completed that, and have a few days before I need to turn the project in, so I thought I'd add a little bit of window dressing to this console solution.

The requirements state for the user to input a pattern to match via the console. I have written a separate class to implement a simple GUI in order to collect that user input. The problem I am having is that while my GUI is waiting for me to enter the pattern, my driver class that calls all of my text searching algorithm classes ( and the GUI class too ) continues to run behind my GUI. This does not last long though, since without a pattern to process, I get a null exception.

Given this simple requirement of waiting for text to be entered, what should I read up on? Do I put my driver class into a thread and have it wait for the GUI class? My knowledge of Threads is minimal at best, so I don't even know if Threads are the best way to solve this.

I need someone to point me in the right direction. :-)

Thanks for the help.

BD


I've got just enough Java knowledge to royally screw everything up. :-)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Seems like your knowledge of GUIs is minimal, too, isn't it? Because the obvious thing to have the GUI is to start off the text searching process. I would envisage a text box where you type in the pattern and a button labelled "Go". There shouldn't ever be anything "waiting" for the GUI.

Or was that what you did? If you want to discuss, then post your code.
Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
I thought this forum was "A friendly place for programming greenhorns!", yet your response leads off with an insult. I expected it to obvious that my GUI knowledge is on par with my Thread knowledge since my assignments are still console based.

As I stated, the GUI I am adding is not part of the core program, just window dressing that is not required. I had hoped to just "tack" that on via a separate simple class, but if I am reading your post correctly, if I add any GUI parts, they will need to be the driver of the program. Is this true, and is my attempt to add a GUI in this manner simply the wrong way to go about it?

I am not looking to have you and the other members debug my code for me, I just want a bit of your knowledge that I can pursue on my own time.

So it boils down to this from my perspective: can I not use a separate GUI class to interrupt my main class? And if this is possible, is it such poor practice that I should avoid it completely and integrate the GUI components into the driver class of my program?

Thank you for your time and attention,

BD
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

Bd Howard wrote:I thought this forum was "A friendly place for programming greenhorns!", yet your response leads off with an insult.

I don't see it as an insult, merely an observation.

I expected it to obvious that my GUI knowledge is on par with my Thread knowledge since my assignments are still console based.

Since you never told us the latter, how can we assume the former?

As I stated, the GUI I am adding is not part of the core program, just window dressing that is not required. I had hoped to just "tack" that on via a separate simple class, but if I am reading your post correctly, if I add any GUI parts, they will need to be the driver of the program. Is this true, and is my attempt to add a GUI in this manner simply the wrong way to go about it?

Your GUI parts definitely need to tell the existing code when to start. It then must wait for the existing code to finish. This waiting should not be done on the Event Dispatcher Thread though; read Concurrency in Swing for more information.

So it boils down to this from my perspective: can I not use a separate GUI class to interrupt my main class? And if this is possible, is it such poor practice that I should avoid it completely and integrate the GUI components into the driver class of my program?

Your approach definitely is the right one. It's the implementation of this approach that is not correct yet.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Having read this a few times ...

Assumptions ..

1. You have a console Java app, that waits for the user to enter a string (and then hit enter?) from System.input??

2. While #1 is waiting for user input, you fire up a little GUI app, that I presume has a text box and a button (or response to Enter key?)

3. You want text entered in #2 sent to #1 ?

4. Both console app, and GUI are in one Class and want them to interact? (Even while #1 is waiting for user input?)

Pat.
Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
I appreciate the response Rob. Following what I thought was Paul's suggested route, I just made the GUI the driver, which then passes the string the user inputs to the former driver class. Everything works like I was hoping it would.

Your link to Concurrency In Swing is what I was really hoping to get from this question thread, so thank you for that. I just did not know what it was called beforehand.

Thank you

BD
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

You're welcome.
 
Don't get me started about those stupid light bulbs.
 
subject: Direction needed on how to harness my run-away program