Trying to build a simple registration form in Java Swing and AWT, but couldn't accomplish what I really want.
Here is the result that I want
Here's the code
import java.awt.*;
import javax.swing.*;
public class MainFrame {
public static void main(String[] args) {
// TODO Auto-generated method stub
// Main Frame
JFrame mainFrame = new JFrame("New Account Registration");
JPanel borderPanel = new JPanel(new BorderLayout());
JPanel gridPanel = new JPanel(new GridLayout(9,2));
JPanel gridGenderPanel = new JPanel(new GridLayout(1,2));
JPanel flowButton = new JPanel(new FlowLayout());
//JLabels
JLabel title = new JLabel("New Account Registration");
JLabel name = new JLabel("Name");
JLabel email = new JLabel("Email Address:");
JLabel createPassword = new JLabel("Create Password:");
JLabel confirmPassword = new JLabel("Confirm Password:");
JLabel gender = new JLabel("Gender:");
JLabel address = new JLabel("Address:");
JLabel state = new JLabel("State:");
JLabel country = new JLabel("Country:");
JLabel phoneNo = new JLabel("Phone No:");
String[] coutriesStrings = { "America", "Japan", "India", "Korea", "Sweden" };
// JTextFields, JRadioButton, JComboBox
JTextField nameField = new JTextField();
JTextField emailField = new JTextField();
JPasswordField passField = new JPasswordField();
JPasswordField confirmPassField = new JPasswordField();
JRadioButton male = new JRadioButton("Male");
JRadioButton female = new JRadioButton("Female");
ButtonGroup group = new ButtonGroup();
group.add(male);
group.add(female);
JTextField addressField = new JTextField();
JComboBox stateBox = new JComboBox(coutriesStrings);
stateBox.setSelectedIndex(1);
JTextField countryField = new JTextField();
JTextField phoneField = new JTextField();
JButton submitButton = new JButton("Submit");
JButton clearButton = new JButton("Clear");
// borderPanel.add(title, BorderLayout.NORTH);
// gridPanel.add(title);
// Name
gridPanel.add(name);
gridPanel.add(nameField);
//Email
gridPanel.add(email);
gridPanel.add(emailField);
// CreatePassword
gridPanel.add(createPassword);
gridPanel.add(passField);
// Confirm Password
gridPanel.add(confirmPassword);
gridPanel.add(confirmPassField);
// Gender
gridGenderPanel.add(gender);
gridGenderPanel.add(male);
gridGenderPanel.add(female);
gridPanel.add(gridGenderPanel);
// Address
gridPanel.add(address);
gridPanel.add(addressField);
// State
gridPanel.add(state);
gridPanel.add(stateBox);
// Country
gridPanel.add(country);
gridPanel.add(countryField);
//Button
flowButton.add(submitButton);
flowButton.add(clearButton);
gridPanel.add(flowButton);
mainFrame.add(gridPanel);
mainFrame.setSize(600, 700);
mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Here is the result of the codes
I don't know where did I do wrong, please guide me.