Results 1 to 6 of 6
Thread: Simple Text Problem
- 04-24-2012, 08:43 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
Simple Text Problem
I am sorry that this is such a simple question but I was just wondering how you have user enter a name into a text box and then print out whatever was placed in that box. I already have the text box and command button in an applet I just do not know how to capture the input and then output it.
Thanks for your patience.
- 04-24-2012, 09:13 PM #2
Re: Simple Text Problem
Please post the code that shows what you have.
Where do you want to output what was entered in the text box?
Look at the API doc for the text box class to see what methods you can use to get its contents.If you don't understand my response, don't ignore it, ask a question.
- 04-24-2012, 09:17 PM #3
Re: Simple Text Problem
What's a text box?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-24-2012, 11:38 PM #4
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
Re: Simple Text Problem
Sorry if I am using the wrong terminology. This is what I have so far
import java.awt.*;
import java.applet.*;
public class GuiExample extends Applet
{
// A Button to click
Button okButton;
// A textField to get text input
TextField nameField;
// A group of radio buttons
// necessary to only allow one radio button to be selected at the same time.
CheckboxGroup radioGroup;
// The radio buttons to be selected
Checkbox radio1;
Checkbox radio2;
// An independant selection box
Checkbox option;
public void init()
{
// Tell the applet not to use a layout manager.
setLayout(null);
// initialze the button and give it a text.
okButton = new Button("A button");
// text and length of the field
nameField = new TextField("A TextField",100);
// initialize the radio buttons group
radioGroup = new CheckboxGroup();
// first radio button. Gives the label text, tells to which
// group it belongs and sets the default state (unselected)
radio1 = new Checkbox("Radio1", radioGroup,false);
// same but selected
radio2 = new Checkbox("Radio2", radioGroup,true);
// Label and state of the checkbox
option = new Checkbox("Option",false);
// now we will specify the positions of the GUI components.
// this is done by specifying the x and y coordinate and
//the width and height.
okButton.setBounds(20,20,100,30);
nameField.setBounds(20,70,100,40);
radio1.setBounds(20,120,100,30);
radio2.setBounds(140,120,100,30);
option.setBounds(20,170,100,30);
// now that all is set we can add these components to the applet
add(okButton);
add(nameField);
add(radio1);
add(radio2);
add(option);
}
}
- 04-24-2012, 11:45 PM #5
Re: Simple Text Problem
You need to add listeners to the buttons so the listener methods will be called when the user presses one of the buttons. Then in the listener method you can get the contents of the text field and print it.
If you don't understand my response, don't ignore it, ask a question.
- 04-25-2012, 12:09 AM #6
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Simple text printing with pagebreaks
By miloshz in forum AWT / SwingReplies: 0Last Post: 05-10-2011, 05:34 PM -
Simple server/client text problem
By Singing Boyo in forum New To JavaReplies: 5Last Post: 06-02-2009, 10:33 AM -
Simple Text race game
By Inf1nity in forum New To JavaReplies: 2Last Post: 03-16-2009, 03:46 PM -
printing simple text as text on printer
By Nicholas Jordan in forum Advanced JavaReplies: 0Last Post: 12-01-2008, 01:42 AM -
Simple: Text to an image & save.
By cilaes in forum Java 2DReplies: 4Last Post: 09-06-2008, 06:16 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks