CS 160

November 20, 2007

The Beauty Pageant for Fall 2007



Next week's lab we will be having a beauty pageant in lab class. You are to create the contestants. Be creative, your peers will be judging.
In the last two lectures I made applets and used the Graphics2D class to draw objects on the screen. I went over the Graphics class using fillRect, drawRect and many more of the drawing capabilities. Plus the MouseListener to handle mouse input.
You have an Outlab due next week that is drawing a head (get as fancy as you want), and adding a little animation. Below is an example of a head I did earlier.

Monday's lecture notes also shows some animation. Last Friday has the first Applet. Use those, as well as this page to create your own person in lab today, and then next week you will show it off and animate it.

No inlab this week. Have a good Thanksgiving

ALT="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." Your browser is ignoring the <APPLET> tag! I wrote the applet twice this code and applet is using the Graphics2D. I included the paint method below. You should use Graphics2D.
  	public void paint(Graphics g)
	{
	Graphics2D g2 = (Graphics2D)g;
        g.drawLine(20, 20, 100, 50);
        g.setColor(Color.green);
        g.setColor(Color.red);
        g.drawLine(20, 100, 100, 50);
        g.drawRect(0, 0, 20, 20);
        g.setColor(Color.blue);
        g.drawRect(20, 100, 50, 60);
	}

This applet is the same program but it's just using the regular Graphics class. YOu should use the Graphics2D class.
   
	public void paint(Graphics g)
	{
		
        g.drawLine(20, 20, 100, 50);
        g.setColor(Color.green);
        g.setColor(Color.red);
        g.drawLine(20, 100, 100, 50);
        g.drawRect(0, 0, 20, 20);
        g.setColor(Color.blue);
        g.drawRect(20, 100, 50, 60);
	}
This an example of a head that I did using Rectangles, ovals, and lines. Your lab is to create a head of your own using the ovals, rects, and anything else in the Graphics classes that you wish to use. You will have a beauty pageant in the lab next week.
I wish each of you the best of luck, be creative. You can do much better than my example below, and remember to animate it.

Can you create the ultimate in Applet Beauty?
I expect you to do much better than the one above.
Advanced topics to include in the OUTLAB:
  • Put in a MouseListener to start an animation when the mouse is clicked in your Applet. You need to do four things to implement a simple MouseListener (You can also reference yesterday's lecture program):
    1. First import the awt event package:
                 import java.awt.event.*;  
              
    2. Next implement the MouseListener, add it to your class definition:
      public class MyApplet extends JApplet implements MouseListener
    3. Next in your init method start the MouseListeners listening to your applet for a mouse command.
              addMouseListener(this);
           
    4. Last include the MouseListener methods in your class. You can put them below your paint method. Each must be included. On this example I put a repaint call in the mouseClicked method, the rest of the methods do nothing, but you have to include all of them if you are implementing the MouseListener interface (you can also use any of them if you want). If the mouse is clicked in the Applet it calls repaint() which will then call paint. You can set an int flag that changes everytime the mouse is clicked to create animation. See example below.
          public void mousePressed(MouseEvent e) {
             repaint();
          }
      
          public void mouseReleased(MouseEvent e) {
             
          }
      
          public void mouseEntered(MouseEvent e) {
             
          }
      
          public void mouseExited(MouseEvent e) {
             
          }
      
          public void mouseClicked(MouseEvent e) {
            
          }
      
  • Here is an example of a animation with a mouse click I just change the X and Y values call repaint() and then draw my rect with the new x and y paramters.
ALT="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." Your browser is ignoring the <APPLET> tag!