Need to add a JCombobox to select the user’s State of birth, and a JRadio buttons to indicate their gender. Also, add a JTextArea to the form. Once the user clicks on the JButton the application will display all of the user’s information in the JTextearea.
All the classes work properly I need to figure out how to get them to work together and properly. Any assistance will be greatly appreciated.
justindillingerHW3.java
package justindillingerhw3;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.TitledBorder;
public class JustinDillingerHW3 extends JFrame{
//Create text fields and labels
private JTextField jtfFirstName = new JTextField(15);
private JTextField jtfLastName = new JTextField(15);
private JTextField jtfAge = new JTextField(2);
private JRadioButton Male;
private JRadioButton Female;
private JLabel WelcomeMessage;
public static void main(String[] args){
JustinDillingerHW3 frame = new JustinDillingerHW3();
frame.setTitle("Hello User!!");
frame.setSize(1000, 1000);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public JustinDillingerHW3(){
setLayout(new FlowLayout(FlowLayout.LEFT, 10, 20));
//add labels and text fields to the frame
add(new JLabel("First Name"));
add(jtfFirstName);
add(new JLabel("Last Name"));
add(jtfLastName);
add(new JLabel("Age"));
add(jtfAge);
//Create Welcome button
JButton Welcome = new JButton("Click Here!!");
add(Welcome);
Welcome.addActionListener(new SubmitListener());
WelcomeMessage = (new JLabel(" "));
add(WelcomeMessage);
}
class SubmitListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String FirstName = jtfFirstName.getText();
String SurName = jtfLastName.getText();
WelcomeMessage.setText("Welcome, " + FirstName + " " + SurName);
}
}
}
createradiobutton.java
package createradiobutton;
import javax.swing.*;
import java.awt.*;
public class CreateRadioButton extends JFrame{
public static void main(String[] args) {
CreateRadioButton radioButton = new CreateRadioButton();
}
public CreateRadioButton(){
JRadioButton Male,Female;
JFrame frame = new JFrame("Gender");
JPanel panel = new JPanel();
//Group radio buttons male & female
ButtonGroup buttonGroup = new ButtonGroup();
Male = new JRadioButton("Male");
buttonGroup.add(Male);
panel.add(Male);
Female = new JRadioButton("Female");
buttonGroup.add(Female);
panel.add(Female);
//Set initial selection to male
Male.setSelected(true);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(250, 250);
frame.setVisible(true);
}
}
createcombobox.java
package createcombobox;
import java.awt.FlowLayout;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class CreateComboBox extends JFrame {
public static void main(String[] args) {
CreateComboBox frame = new CreateComboBox();
frame.setTitle("States");
frame.setSize(200, 100);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public CreateComboBox(){
JComboBox jComboBox1 = new JComboBox();
jComboBox1.addItem("Alabama");
jComboBox1.addItem("Alaska");
jComboBox1.addItem("Arizona");
jComboBox1.addItem("Arkansas");
jComboBox1.addItem("California");
jComboBox1.addItem("Colorado");
jComboBox1.addItem("Connecticut");
jComboBox1.addItem("Delaware");
jComboBox1.addItem("Florida");
jComboBox1.addItem("Georgia");
jComboBox1.addItem("Hawaii");
jComboBox1.addItem("Idaho");
jComboBox1.addItem("Illinois");
jComboBox1.addItem("Indiana");
jComboBox1.addItem("Iowa");
jComboBox1.addItem("Kansas");
jComboBox1.addItem("Kentucky");
jComboBox1.addItem("Louisiana");
jComboBox1.addItem("Maryland");
jComboBox1.addItem("Massachusetts");
jComboBox1.addItem("Michigan");
jComboBox1.addItem("Minnesota");
jComboBox1.addItem("Mississippi");
jComboBox1.addItem("Missouri");
jComboBox1.addItem("Montana");
jComboBox1.addItem("Nebraska");
jComboBox1.addItem("Nevada");
jComboBox1.addItem("New Hampshire");
jComboBox1.addItem("New Jersey");
jComboBox1.addItem("New Mexico");
jComboBox1.addItem("New York");
jComboBox1.addItem("North Carolina");
jComboBox1.addItem("North Dakota");
jComboBox1.addItem("Ohio");
jComboBox1.addItem("Oklahoma");
jComboBox1.addItem("Oregon");
jComboBox1.addItem("Pennsylvania");
jComboBox1.addItem("Rhode Island");
jComboBox1.addItem("South Carolina");
jComboBox1.addItem("South Dakota");
jComboBox1.addItem("Tennessee");
jComboBox1.addItem("Texas");
jComboBox1.addItem("Utah");
jComboBox1.addItem("Vermont");
jComboBox1.addItem("Virginia");
jComboBox1.addItem("Washington");
jComboBox1.addItem("West Virginia");
jComboBox1.addItem("Wisconsin");
jComboBox1.addItem("Wyoming");
Object StateList = jComboBox1.getSelectedItem();
System.out.println(StateList);
add(jComboBox1);
}
}
createtextarea.java
package createtextarea;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.*;
public class CreateTextArea {
public static void main(String[] args){
JFrame frame= new JFrame("Output Frame");
JPanel panel=new JPanel();
JTextArea jt= new JTextArea("Hello everybody in CMIS-242", 5, 20);
frame.add(panel);
panel.add(jt);
frame.setSize(250,200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Please help me figure this out.