package divelog; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.Color.*; public class Diver extends JPanel implements ActionListener { // Opens class // Fields for Diver Personal Information // Text fields for user input private JTextField name; private JTextField street; private JTextField city; private JTextField statezip; // Labels to go with each text field private JLabel lname; private JLabel lstreet; private JLabel lcity; private JLabel lstatezip; // Check boxes for types of diver training private JCheckBox ow; private JCheckBox a; private JCheckBox res; private JCheckBox un; private JCheckBox w; // Textfields for Emergency box private JTextField nname; private JTextField phone; private JTextField rel; // Textfields for Emergency Contact private JLabel lnname; private JLabel lphone; private JLabel lrel; // Buttons and image private JButton enter; private JButton edit; private JLabel seahorse; // Panels to be built and added // to the border layout of this // panel. private JPanel images; private JPanel jaddress; private JPanel emerg; private JPanel training; // Class to handle functionality of checkboxes ItemListener handler = new CheckBoxHandler(); // Class constructor that builds the necessary // labels and text fields images, buttons, // and panels. public Diver() { // Opens Constructor // Sets layout for Diver panel setLayout(new BorderLayout()); // Sets background color for // Diver panel setBackground(Color.white); // Initializes textfields name = new JTextField("Enter Your Name"); street = new JTextField(); city = new JTextField (); statezip = new JTextField (); // Initializes labels for textfields lname = new JLabel("Name: "); lstreet = new JLabel("Street: "); lcity = new JLabel ("City: "); lstatezip = new JLabel("State & Zip Code: "); // Initializes checkboxes with titles ow = new JCheckBox("Open Water", true); a = new JCheckBox("Advanced"); res = new JCheckBox("Recovery & Rescue"); un = new JCheckBox("Underwater Photography"); w = new JCheckBox("Wreck & Cave Diving"); // Initializes textfields for emergency panel nname = new JTextField(); phone = new JTextField(); rel = new JTextField (); // Initializes labels for textfields lnname = new JLabel("Name: "); lphone = new JLabel("Phone: "); lrel = new JLabel ("Relationship: "); // Initialize objects enter = new JButton("Enter Diver Data"); edit = new JButton("Edit Diver Data"); seahorse = new JLabel("", new ImageIcon("images/2seahorses.jpg"), JLabel.CENTER); // Calls method to buid image panel, which // is defined outside of the constructor buildImagePanel(); // Calls method to buid address panel, which // is defined outside of the constructor buildAddressPanel(); // Calls method to buid emerg panel, which // is defined outside of the constructor buildEmergencyPanel(); // Calls method to buid training panel, which // is defined outside of the constructor buildTrainingPanel(); //The methods called above build the panels, then this // call to add adds each panel to the main panel's // border layout manager. add(jaddress, BorderLayout.NORTH); add(images, BorderLayout.CENTER); add(training, BorderLayout.EAST); add(emerg, BorderLayout.SOUTH); } // Ends constructor // This method creates a panel called images private void buildImagePanel() { // Opens method // Instantiates a new JPanel object images = new JPanel(); // Sets the color, layout, and adds the // seahorse object images.setLayout(new FlowLayout() ); images.setBackground(Color.white); images.add(seahorse); } // Closes method private void buildAddressPanel () { // Opens method jaddress = new JPanel(); // Sets color and layout. // Adds the textfields and labels for // diver input. jaddress.setBackground(Color.white); jaddress.setLayout( new GridLayout(2, 4, 20, 20) ); //Adds each component to the panel jaddress.add(lname); jaddress.add(name); jaddress.add(lstreet); jaddress.add(street); jaddress.add(lcity); jaddress.add(city); jaddress.add(lstatezip); jaddress.add(statezip); // Sets a border around the panel, including // a title jaddress.setBorder(BorderFactory.createTitledBorder( "Diver Personal Information")); //Listeners for each text field in the name.addActionListener( this ); street.addActionListener( this ); city.addActionListener( this ); statezip.addActionListener( this ); } // Closes method }// Closes class