Java Reference
In-Depth Information
//First quadrant
quadrants[0].setBackground(Color.RED);
current = 0;
}
else if(x > width/2 && y < height/2)
{
//Second quadrant
quadrants[1].setBackground(Color.GREEN);
current = 1;
}
else if(x < width/2 && y > height/2)
{
//Third quadrant
quadrants[2].setBackground(Color.BLUE);
current = 2;
}
else if(x > width/2 && y > height/2)
{
//Fourth quadrant
quadrants[3].setBackground(Color.YELLOW);
current = 3;
}
for(int i = 0; i < quadrants.length; i++)
{
if(i != current)
{
quadrants[i].setBackground(Color.WHITE);
}
}
}
}
Figure 14.2 shows the output of the HelloSwingApplet in a Web page
named colors.html, which is defined as:
<html>
<body>
<p>Move the mouse around the applet.</p>
<applet code=”HelloSwingApplet”
width=”300”
height=”300”>
</applet>
</body>
</html>
Search WWH ::




Custom Search