Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Simple Text Problem

  1. #1
    shodai is offline Senior Member
    Join Date
    Apr 2012
    Posts
    106
    Rep Power
    0

    Default 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.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default 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.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: Simple Text Problem

    What's a text box?

    db
    jlczuk likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    shodai is offline Senior Member
    Join Date
    Apr 2012
    Posts
    106
    Rep Power
    0

    Default 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);
    }

    }

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default 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.

  6. #6
    shodai is offline Senior Member
    Join Date
    Apr 2012
    Posts
    106
    Rep Power
    0

    Default 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.

Similar Threads

  1. Simple text printing with pagebreaks
    By miloshz in forum AWT / Swing
    Replies: 0
    Last Post: 05-10-2011, 05:34 PM
  2. Simple server/client text problem
    By Singing Boyo in forum New To Java
    Replies: 5
    Last Post: 06-02-2009, 10:33 AM
  3. Simple Text race game
    By Inf1nity in forum New To Java
    Replies: 2
    Last Post: 03-16-2009, 03:46 PM
  4. printing simple text as text on printer
    By Nicholas Jordan in forum Advanced Java
    Replies: 0
    Last Post: 12-01-2008, 01:42 AM
  5. Simple: Text to an image & save.
    By cilaes in forum Java 2D
    Replies: 4
    Last Post: 09-06-2008, 06:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •