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

Norm

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.

04-24-2012, 09:17 PM

DarrylBurke

Re: Simple Text Problem

What's a text box?

db

04-24-2012, 11:38 PM

shodai

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

Norm

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.

04-25-2012, 12:09 AM

shodai

Re: Simple Text Problem

That is perfect. I was able to find exactly what I needed. I just did not know the language to use or what type of process that I needed. Thanks so much.