Exp 11
Exp 11
Exp 11
X.Program Code
1. Ans
OUTPUT:
XII Exercise
1. Ans
CODE:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
@Override
public void mousePressed(MouseEvent e) {
setBackground(Color.RED);
}
@Override
public void mouseReleased(MouseEvent e) {
setBackground(Color.GREEN);
}
@Override
public void mouseEntered(MouseEvent e) {
setBackground(Color.YELLOW);
}
@Override
public void mouseExited(MouseEvent e) {
setBackground(Color.BLUE);
}
@Override
public void mouseClicked(MouseEvent e) {
setBackground(Color.CYAN);
}
}
HTML CODE:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</applet>
</body>
</html>
OUTPUT:
XIII. Exercise
2. Ans
CODE:
import javax.swing.*;
import java.awt.event.*;
public ClickCounter() {
setTitle("Click Counter");
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
add(label);
addMouseListener(this);
setVisible(true);
@Override
clickCount++;
}
@Override
@Override
@Override
@Override
new ClickCounter();
OUTPUT:
XIII.Exercise
3. Ans
CODE:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public MouseMotionDemo() {
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
add(label);
addMouseMotionListener(this);
setVisible(true);
@Override
}
@Override
new MouseMotionDemo();
OUTPUT: