import java.util.Scanner;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.awt.HeadlessException;

/**
 * Just creating some objects of various classes
 *
 * @author Mark Young (A00000000)
 */
public class ObjectClasses {

    public static void main(String[] args) {
        // declare some objects
        String s1, s2;
        Scanner kbd, str;
        Animal rover, hammy;
        Color c1, c2;
        JButton okButton, cancelButton;
        JFrame win;

        // create some objects
        kbd = new Scanner(System.in);
        str = new Scanner("This is the String this Scanner scans!");
        rover = new Animal(Animal.DOG, "Rover");
        hammy = new Animal(Animal.HAMSTER, "Hammy");
        c1 = new Color(255, 127, 0);
        c2 = new Color(17, 79, 251);
        okButton = new JButton("OK");
        cancelButton = new JButton("Cancel");
        s1 = "Strings are special!";
        s2 = new String("But this works, too!");

        // access some object data
        System.out.printf("\"%s\".length() is %d.\n", s1, s1.length());
        System.out.printf("\"%s\".charAt(0) is '%c'.\n", s1, s1.charAt(0));
        System.out.printf("\"%s\".charAt(1) is '%c'.\n", s1, s1.charAt(1));
        System.out.printf("\"%s\".charAt(2) is '%c'.\n", s1, s1.charAt(2));
        System.out.printf("\"%s\".charAt(2) is '%c'.\n", s2, s2.charAt(2));
        System.out.printf("%s's species is %s.\n", 
                            rover.getName(), rover.getSpecies());
        System.out.printf("%s's species is %s.\n", 
                            hammy.getName(), hammy.getSpecies());

        // NOTE:  You do not need to understand ANY of the following code.
        // It's just here so I can show you the colors and buttons I created.

        try {
            // create a window to show some of the other objects
            win = new JFrame("This window has two buttons");    // title of window
            win.setSize(300, 200);  // make window big enuf to see!

            // change colors of the buttons
            okButton.setBackground(c1); // orange background
            cancelButton.setBackground(c2); // blue background
            cancelButton.setForeground(new Color(255, 255, 0)); // yellow text

            // make the cancel button exit the program (OK button does nothing!)
            cancelButton.addActionListener(e -> System.exit(0));

            // put the buttons and a label into the window
            win.getContentPane().add(okButton, BorderLayout.NORTH); // at top
            win.getContentPane().add(cancelButton, BorderLayout.SOUTH); // at bottom
            win.getContentPane().add(new JLabel("And the buttons have colors!"), 
                    BorderLayout.CENTER);   // in the middle

            // show the window we just created
            win.setVisible(true);

            // program won't end until user clicks cancel button
        } catch (HeadlessException he) {
            Utilities.printParagraph("I'm sorry. I have a demo of a window "
                    + "with buttons and labels and colours, but the system "
                    + "you're using can't show it. Try again using a GUI.");
        }
    }

}
