John
2012-08-19 16:31:37 UTC
import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.*;
import java.awt.*;
import java.awt.Color;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.awt.Color;
import java.util.Random;
public class Color_Change extends JPanel implements MouseListener{
private JLabel one, two, three, four;
Random colorz = new Random();
Color_Change(){
this.setLayout(new BorderLayout());
this.setBackground(Color.white);
JPanel centerPanel = new JPanel(new FlowLayout());
one = new JLabel();
Dimension myLabel = new Dimension(100, 100);
one.setPreferredSize(myLabel);
one.setBackground(Color.white);
one.setOpaque(true);
one.addMouseListener(this);
centerPanel.add(one);
two = new JLabel();
Dimension myLabel2 = new Dimension(100, 100);
two.setPreferredSize(myLabel2);
two.setBackground(Color.red);
two.setOpaque(true);
two.addMouseListener(this);
centerPanel.add(two);
three = new JLabel();
Dimension myLabel3 = new Dimension(100, 100);
three.setPreferredSize(myLabel3);
three.setBackground(Color.blue);
three.setOpaque(true);
three.addMouseListener(this);
centerPanel.add(three);
four = new JLabel();
Dimension myLabel4 = new Dimension(100, 100);
four.setPreferredSize(myLabel4);
four.setBackground(Color.pink);
four.setOpaque(true);
four.addMouseListener(this);
centerPanel.add(four);
this.add(centerPanel, BorderLayout.CENTER);
}
public void mouseEntered(MouseEvent me)
{
if(me.getSource().equals (one))
{
}
if(me.getSource().equals (two))
{
}
if(me.getSource().equals (three))
{
}
if(me.getSource().equals (four))
{
}
}
public void mouseExited(MouseEvent me)
{
}
public void mousePressed(MouseEvent me)
{
}
public void mouseReleased(MouseEvent me)
{
}
public void mouseClicked(MouseEvent me)
{
}
public static void main(String[] args)
{
JFrame application = new JFrame(" ? ");
Color_Change panel = new Color_Change();
application.add(panel);
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.setSize(300,300);
application.setVisible(true);
}
}
Thank You