aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Help With a simple GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help With a simple GUI" Watch "Help With a simple GUI" New topic
Author

Help With a simple GUI

Samuel Weston
Ranch Hand

Joined: Oct 24, 2013
Posts: 31
hey, i'm trying to create a program that results in 2 GUI's. the first would be a prompt for the user to input information, and the second would have the inputted information as well as a few sentences-appear on it.

my real goal isn't the result so much as understanding the process of making GUI output based on the user's input as opposed to the programmers.
that being the case, i'm not looking for a package to do my work for me, I'm looking to make the code from (relative) scratch...

to do this, I tried manipulating the code for GUI that I happened to know-to include the Scanner class, that is, to allow for the users input...but its not working.

for all intents and purposes, assume all output (e.g all 'println') are meant to be on the GUI

also, I kept my notes in there, I hope they're more helpful than distracting
(read them as a reflection of my thought process. they in no way dictate the "correct" way of carrying my goals out)

heres the first class



the second class
//this is the execution class for SequenceOptions



darn. i want to put the users name onto the GUI but the Scanner code is outside the GUI coding
Im SURE this has been dealt with before. the basic question is
1)how make a GUI that prints Scannernextline or whatever
2)how do i make multiple GUI without having to write the same code over and over?
my aim is to make one pane a prompt for user name
and a second pane that outputs the inputted name (as well as other words)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39869
    
  28
I shall move this discussion to our GUIs forum.

Don't attempt to combine logic and display. The GUI classes are for display and there are other classes for the logic. Make sure to keep them separate. You should not therefore use a Scanner or System.out as well as the GUI. You should get the logic working before you try going near the GUI. You can have a class like thisAnd you call it like this:-When you have that sort of thing working, then consider a GUI. I suggest you have a controlling class which has a NameMessage object and a GUI as fields. You can enter the name in something like a text field and print the message to a label. You will want a button or menu item or similar to create a new NameMessage object and display its message.
But once you start using a GUI, use that exclusively. And when I said a GUI I meant a GUI. You do not want two GUIs in one application. You can have several components in the same frame, or show dialogue windows, but don't attempt to use two frames.
Rico Felix
Ranch Hand

Joined: Mar 08, 2014
Posts: 304
    
    4

Instead of repeating stuff that has already been explained, I'll point you to the API Documentation as well as the Java Tutorials

If after searching through the content provided you haven't found a solution to your problem, I will try to lead you in a direction if someone else hasn't.
Rico Felix
Ranch Hand

Joined: Mar 08, 2014
Posts: 304
    
    4

Here is a quick demonstration using some code of what I assume you are trying to achieve:


The main focus is on the label's setText(String) method and the JOptionPane's showInputDialog(Component, Object) method.

You can use this example along with the references that I've provided and you should be on your way to solving your problem and walking away with new knowledge.
Samuel Weston
Ranch Hand

Joined: Oct 24, 2013
Posts: 31
thank you everyone (Campell Ritchie and Rico Felix)
you've given me something to mull over and play around with
thank you very very much
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39869
    
  28
Nice suggestion, RF. I was thinking of a text field for input, so the two are rather different.
Rico Felix
Ranch Hand

Joined: Mar 08, 2014
Posts: 304
    
    4

Thank you sheriff!!

The text field I'm sure is what he'd go for and he should... I've only used the label and button combination to demonstrate a simple and quick application for the functionality that I'm assuming he's looking for... I've also deliberately chosen those two so he can implement the real stuff on his own...
 
wood burning stoves
 
subject: Help With a simple GUI