Loyola College in Maryland

CS 202 - Computer Science II
Fall 2004


Loyola College > Department of Computer Science > Dr. James Glenn > CS 202 > Homework > Homework #2

Due: Monday, October 11th at the beginning of class

Read: Koffman & Wolz, Chapter 7

  1. p. 454, Programming Exercise #1
  2. p. 461, Programming Exercise #1
  3. Write an applet like the following
    Start with the following skeleton:
    import javax.swing.*;
    import java.awt.*;
    
    // add the appropriate import here
    
    public class RandomColors extends JApplet // implement the right interface here
    {
      private JPanel colorPanel;
    
      public void init()
      {
        JPanel buttonPanel;
        buttonPanel = new JPanel(new FlowLayout());
        colorPanel = new JPanel(new FlowLayout());
    
        // create the button here
    
        getContentPane().setLayout(new BorderLayout());
    
        // add inner panels to the applet here    
      }
    
      // add an event handler here
    
      public Color makeRandomColor()
      {
        int red = (int)(Math.random() * 256);    
        int green = (int)(Math.random() * 256);
        int blue = (int)(Math.random() * 256);
    
        return new Color(red, green, blue);
      }
    }