Sample Program With GUI
Sample Program With GUI
Code:
//Address Label
JLabel lblAdd = new JLabel("Address:");
lblAdd.setHorizontalAlignment(SwingConstants.RIGHT);
lblAdd.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblAdd.setBounds(10, 69, 88, 25);
contentPane.add(lblAdd);
//Age Label
JLabel lblAge = new JLabel("Age:");
lblAge.setHorizontalAlignment(SwingConstants.RIGHT);
lblAge.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblAge.setBounds(10, 104, 88, 25);
contentPane.add(lblAge);
//Gender Label
JLabel lblGender = new JLabel("Gender:");
lblGender.setHorizontalAlignment(SwingConstants.RIGHT);
lblGender.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblGender.setBounds(10, 139, 88, 25);
contentPane.add(lblGender);
//initializing the value of appName, add, and age from the Text Field
appName = txtName.getText();
add = txtAddress.getText();
age = txtAge.getText();
//initializing the value of program from the selected item on the combo box
//(String) is used to convert the selected item from Object to String
program = (String)cmbProgram.getSelectedItem();
//to show message dialog for the user to confirm the information
JOptionPane.showMessageDialog(contentPane, "Confirm your input"
+ "\nName: " + appName
+ "\nAddress: " + add
+ "\nAge: " + age
+ "\nProgram Choice: " + program);
Sample Output: