News:

Build a stunning handcrafted website with IT Acumens

Main Menu

Simple Class Program in Java

Started by Kalyan, Dec 10, 2008, 07:30 AM

Previous topic - Next topic

Kalyan

Simple Class Program in Java

import java.awt.*;
import java.awt.event.*;

public class HandlingLabels extends Frame implements MouseListener
{
Label l1 = new Label("First");
Label l2 = new Label("Second");

public HandlingLabels()
{
super("Handling Labels");
setSize(200,300);
setLayout(new FlowLayout());
add(l1);
add(l2);
l1.addMouseListener(this);
l2.addMouseListener(this);
setVisible(true);
}

public void mousePressed(MouseEvent me) { }

public void mouseClicked(MouseEvent me) { }

public void mouseReleased(MouseEvent me) { }

public void mouseEntered(MouseEvent me)
{
if(me.getSource() == l1)
l1.setText("On Me");
else
l2.setText("On Me");
}

public void mouseExited(MouseEvent me)
{
if(me.getSource() == l1)
l1.setText("First");
else
l2.setText("Second");
}

public static void main(String args[])
{
new HandlingLabels();
}
}