ColorChangePanel - setBackground(shade); center =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // ColorChangePanel.java Author: Lewis and Loftus / Alicia Nicol // // Solution to Programming Project 7.14 //******************************************************************** / import javax.swing.*; import java.awt.*; import java.awt.event.*; i public class ColorChangePanel extends JPanel { private Color shade; int center; //----------------------------------------------------------------- // Initializes the panel //----------------------------------------------------------------- public ColorChangePanel() { addMouseMotionListener(new MoveListener()); shade = Color.green; setBackground (shade); } //----------------------------------------------------------------- // Draws a center line and paints the rectangle in the current // color. //----------------------------------------------------------------- public void paintComponent (Graphics page) { super.paintComponent(page);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: setBackground(shade); center = getWidth() / 2; page.setColor (Color.white); page.drawLine (center, 0, center, getHeight()); } //***************************************************************** // Represents the listener for the mouse clicks //***************************************************************** private class MoveListener extends MouseMotionAdapter { //-----------------------------------------------------------------// Switches the color and repaints the applet if necessary based // on the current mouse location. //-----------------------------------------------------------------public void mouseMoved (MouseEvent event) { Point location = event.getPoint(); if (location.x < center) { if (shade.equals(Color.green)) { shade = Color.red; repaint(); } } else if (shade.equals(Color.red)) { shade = Color.green; repaint(); } } } }...
View Full Document

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Page1 / 2

ColorChangePanel - setBackground(shade); center =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online