Java Reference
In-Depth Information
import java.applet.*;
import java.awt.*;
import javax.swing.*;
public class HelloSwingApplet extends JApplet
{
public void init()
{
Container contentPane = this.getContentPane();
contentPane.setLayout(new GridLayout(2,2));
JPanel [] quadrants = new JPanel[4];
for(int i = 0; i < quadrants.length; i++)
{
quadrants[i] = new JPanel();
contentPane.add(quadrants[i]);
}
FourColors listener = new FourColors(quadrants,
this.getWidth(), this.getHeight());
this.addMouseMotionListener(listener);
}
}
import java.awt.*;
import java.awt.event.*;
public class FourColors extends MouseMotionAdapter
{
private Container [] quadrants;
private int width, height;
public FourColors(Container [] q, int w, int h)
{
quadrants = q;;
width = w;
height = h;
}
public void mouseMoved(MouseEvent m)
{
int x = m.getX();
int y = m.getY();
int current = 0;
if(x < width/2 && y < height/2)
{
Search WWH ::




Custom Search