• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Direction needed on how to harness my run-away program

 
Bd Howard
Greenhorn
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Clapham
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic