Results 1 to 2 of 2
  1. #1
    romina is offline Member
    Join Date
    Jul 2007
    Rep Power

    Default I'm trying to add a separate dialog to a Java program...

    I'm trying to add a separate dialog/window to a Java program that collects the user's information from three different text boxes.

    I have looked at the sun tutorial, swing textbooks, and a graphic java text, but I'm still confused.

    How do I layout the three textboxes and the four related labels in the dialog? And how do I get this information from the dialog/window and send it back to the main frame in a single string (e.g. textbox1+textbox2+textbox3)?

  2. #2
    trill is offline Member
    Join Date
    Jul 2007
    Rep Power


    I recommend you start off with only one textbox and a label. After you complete it, experiment a bit with more labels and boxes..

    Here is how you would add a JTextfield and a JLabel. Note you will still need to create a main class:
    Java Code:
    import java.awt.*;
    import java.awt.event;
    import javax.swing.*;
    public class YouClassNameHere extends JPanel{
        private JLabel YourInputLabel;
        private JTextfield YourTextField;
        public YourClassNameHere(){
            YourInputLabel = new JLabel("You write something here");
            YourTextField = new JTextField(#); //where # is any number. Gives a size to the TextField.
            YourTextField.addActionListener(new TempListener());//this will tell the program that you want to interact with it.
            add (YourInputLabel);
            setPreferredSize(new Dimension(300,75));
            setBackground (Color.yellow);
    //Then just add a TempListener class. Inside this class, you might want
    //to define some variables, and perform some operations.
    As far as joining the inputs, you can do it this way
    Java Code:
    String String1 = new String("Hello");
    String String2 = new String("World!");
    String String3 = new String(String1 + " " + String2); //Creates a new String with the values of String1 and String2

Similar Threads

  1. Hash table with separate chaining
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 08:42 PM
  2. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  3. Dialog typeface outside Java
    By Dreen in forum New To Java
    Replies: 1
    Last Post: 11-19-2007, 08:35 AM
  4. Replies: 0
    Last Post: 10-04-2007, 09:33 PM
  5. Java Print Dialog Framework 1.7
    By levent in forum Java Software
    Replies: 0
    Last Post: 06-19-2007, 05:07 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