package layout;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.SpringLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
public class testing2 extends JPanel implements ActionListener {
JTextField textField = new JTextField("", 15);
protected static JButton b1;
protected JButton b2, b3;
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("SpringDemo2");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Set up the content pane.
Container contentPane = frame.getContentPane();
SpringLayout layout = new SpringLayout();
contentPane.setLayout(layout);
//Create and add the components.
JLabel label = new JLabel("Username: ");
JTextField textField = new JTextField("", 15);
JLabel label2 = new JLabel("Password: ");
JPasswordField textField2 = new JPasswordField("", 15);
JLabel label3 = new JLabel("Re-enter Password: ");
JPasswordField textField3 = new JPasswordField("", 15);
JLabel label4 = new JLabel("Email Address: ");
JTextField textField4 = new JTextField("", 15);
b1 = new JButton("Finish");
b1.setVerticalTextPosition(AbstractButton.CENTER);
b1.setHorizontalTextPosition(AbstractButton.LEADING);
b1.setMnemonic(KeyEvent.VK_F);
b1.setActionCommand("Finish");
contentPane.add(label);
contentPane.add(textField);
contentPane.add(label2);
contentPane.add(textField2);
contentPane.add(label3);
contentPane.add(textField3);
contentPane.add(label4);
contentPane.add(textField4);
contentPane.add(b1);
//SET HEIGHT/WIDTH
layout.putConstraint(SpringLayout.WEST, label,
5,
SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, label,
5,
SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.WEST, textField,
56,
SpringLayout.EAST, label);
layout.putConstraint(SpringLayout.NORTH, textField,
5,
SpringLayout.NORTH, contentPane);
//END SET HEIGHT/WIDTH
//SET HEIGHT/WIDTH
layout.putConstraint(SpringLayout.WEST, label2,
5,
SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, label2,
33,
SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.WEST, textField2,
57,
SpringLayout.EAST, label2);
layout.putConstraint(SpringLayout.NORTH, textField2,
33,
SpringLayout.NORTH, contentPane);
//END SET HEIGHT/WIDTH
//SET HEIGHT/WIDTH
layout.putConstraint(SpringLayout.WEST, label3,
5,
SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, label3,
61,
SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.WEST, textField3,
5,
SpringLayout.EAST, label3);
layout.putConstraint(SpringLayout.NORTH, textField3,
61,
SpringLayout.NORTH, contentPane);
//END SET HEIGHT/WIDTH
//SET HEIGHT/WIDTH
layout.putConstraint(SpringLayout.WEST, label4,
5,
SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, label4,
89,
SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.WEST, textField4,
32,
SpringLayout.EAST, label4);
layout.putConstraint(SpringLayout.NORTH, textField4,
89,
SpringLayout.NORTH, contentPane);
//END SET HEIGHT/WIDTH
//SET HEIGHT/WIDTH
layout.putConstraint(SpringLayout.WEST, b1,
125,
SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, b1,
120,
SpringLayout.NORTH, contentPane);
//END SET HEIGHT/WIDTH
//Display the window.
frame.pack();
frame.setSize(325, 200);
frame.setVisible(true);
}
[B]
public void actionPerformed(ActionEvent e) {
if ("Finish".equals(e.getActionCommand())) {
String x = textField.getText(); This piece of code here does nothing. :(
System.out.println(x);
}
}
[/B]
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}