GUI with Try Catch

I have to write a program, it must be GUI, employ at least one try-catch block, have two distinct interactions witha at least 2 questions each. There must be an OK and ESit button.
Program ask user "Do you like sports?" User answer Y or N (if anything else is entered program needs to catch it and reply with error message and allow interaction to continue.) Question 2 is based on answer from one. If yes then"Is it hockey?", if no Then
Program then asks user "Do you like music?"
if user says Y
Then program asks "Is it jazz?"
I can't even get the GUI right to try to write the rest. Please help.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class week5_3 extends JFrame
      private JTextField inputTF;
      private JButton okayB, exitB;

      private OkayButtonHandler obHandler;
      private ExitButtonHandler ebHandler;
      private static final int WIDTH = 400;
      private static final int HEIGHT = 300;
      public week5_3()
                              //Create text field
            inputTF = new JTextField(10);
                              //Create Okay Button
            okayB = new JButton("Okay");
            obHandler = new OkayButtonHandler();
                              //Create Exit Button
            exitB = new JButton("Exit");
            ebHandler = new ExitButtonHandler();
                              //Set the title of the window
            setTitle("Week 5 Assignment 3");
                              //Get container
            Container pane = getContentPane();
                              //Set the layout
            pane.setLayout (new GridLayout(2, 2));
                              //Place the components in the pane
            private class OkayButtonHandler implements ActionListener
                  public void actionPerformed(ActionEvent e)

            private class ExitButtonHandler implements ActionListener
                  public void actionPerformed(ActionEvent e)
            public static void main(String[] args)
                        week5_3 rectObject = new week5_3();
Who is Participating?
You could just use JOptionPane.showInputDialog - that's a GUI ;-)
Jim CakalicSenior Developer/ArchitectCommented:
You need to call pack() and show() on rectObject after it is created in main.
Mayank SAssociate Director - Product EngineeringCommented:
:-) I like CEHJ's idea.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.