Your grade on lab 7 is: 100

Deductions:

None, great job.


If you have any comments or questions, please speak with me personally or contact me via e-mail at lfallow@clemson.edu.  If I am unable to satisfy your concerns, please contact Miss Sarah Matzko.

Your code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*
 *		Created on Feb 13, 2007 2:23:06 PM
 */

public class ListeningFrame extends JFrame {
   Color shapeColor;
   int x, y, width, height;
   Point location;
   
   public ListeningFrame (String name) {
      super (name);
      setSize (300, 300);
      setDefaultCloseOperation (EXIT_ON_CLOSE);

      shapeColor = Color.BLACK;
      x = y = 0;
      width = height = 0;
      location = getLocation();

      //anonymous class with two methods
      addWindowListener(new WindowAdapter()
      {
         //what happens when the window is closed
         public void windowClosing(WindowEvent e)
         {
           JOptionPane.showMessageDialog(ListeningFrame.this,"Bye-Bye");
         }
         //what happens when the window is opened
         public void windowOpened(WindowEvent e)
         {
            shapeColor = Color.blue;
            height = getHeight();
            width = getWidth();
            x = 0;
            y = 0;
            repaint();
         }
      });

      //changes color when the window changes focus
      addWindowFocusListener(new WindowAdapter()
      {
         //changes to blue when the window is active
         public void windowGainedFocus(WindowEvent e)
         {
            shapeColor = Color.blue;
            repaint();
         }
         //changesto red when the window is not-active
         public void windowLostFocus(WindowEvent e)
         {
            shapeColor = Color.red;
            repaint();
         }
      });
     
     addComponentListener(new ComponentAdapter()
     {
         // changes the size of the shape when the window changes
         public void componentResized(ComponentEvent e)
         {
            
            height = getHeight();
            width = getWidth();
            repaint();
         }
         
         //when the window is moved repaint is called
         public void componentMoved(ComponentEvent e)
         {
            repaint();
         }
     });

             
      setVisible (true);
   }
   
   public void paint (Graphics g) {
      super.paint (g);
      g.setColor (shapeColor);
      g.fillRect (x, y, width, height);
   }

   public static void main (String []args) {
      new ListeningFrame ("Lab 7");
   }
}
