PDA

View Full Version : Java - Complex Dialogs


Seawalker0903
08-03-2006, 05:45 AM
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've 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)?

daniel_g
08-04-2006, 06:54 AM
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:

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);
add(YourTextField);
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

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
System.out.println(String3);