Question: Using the GUI classes, rather than Scanner....Make a program which displays an appropriate name for a person, using a combination of nested ifs and compound

Using the GUI classes, rather than Scanner....Make a program which displays an appropriate name for a person, using a combination of nested ifs and compound conditions. Ask the user for a gender, first name, last name and age. If the person is female and 20 or over, ask if she is married. If so, display "Mrs." in front of her name. If not, display "Ms." in front of her name. If the female is under 20, display her first and last name. If the person is male and 20 or over, display "Mr." in front of his name. Otherwise, display his first and last name. Note that asking a person if they are married should only be done if they are female and 20 or older, which means you will have a single if and else nested inside one of your if statements. using java programming, can someone help me please?

i did started but i got stuck:

import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JTextField; import javax.swing.JLabel; import javax.swing.ButtonGroup; import javax.swing.JRadioButton; import javax.swing.JOptionPane;

public class ButtonExample {

public static void main(String[] args) { JFrame f=new JFrame("Our Frame"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// // // JButton b=new JButton("Click Me"); b.setBounds(100,170,95,30); f.add(b); JTextField tf =new JTextField("Welcome! Type!"); tf.setBounds(100,300, 100,30); f.add(tf); JLabel label =new JLabel("I don't change at all"); label.setBounds(100,270, 150,30); f.add(label); ButtonGroup bg=new ButtonGroup(); JRadioButton r1=new JRadioButton("Male"); JRadioButton r2=new JRadioButton("Female"); r1.setBounds(75,50,100,30); r2.setBounds(75,100,100,30); bg.add(r1); bg.add(r2); f.add(r1); f.add(r2); b.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(tf.getText()); tf.setText("Hi there!"); if(r2.isSelected()){ JOptionPane.showMessageDialog(f,"You're female!"); } } }); f.add(tf); f.setSize(400,600); f.setLayout(null); f.setVisible(true); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!