import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
public class listener extends JFrame implements MouseListener {
public listener() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 500);
setLocation(300, 150);
setAlwaysOnTop(true);
setResizable(false);
setTitle("[" + getHeight() + " : " + getWidth() + "]");
listener.this.addMouseListener(this);
}
public void mouseClicked(MouseEvent e) {
this.getContentPane().setBackground(Color.YELLOW);
}
public void mousePressed(MouseEvent e) {
this.getContentPane().setBackground(Color.BLUE);
}
public void mouseReleased(MouseEvent e) {
this.getContentPane().setBackground(Color.RED);
}
public void mouseEntered(MouseEvent e) {
this.getContentPane().setBackground(Color.DARK_GRAY);
}
@Override
public void mouseExited(MouseEvent e) {
this.getContentPane().setBackground(Color.GREEN);
}
public static void main(String[] args) {
listener list = new listener();
list.setVisible(true);
}
}
Hasilnya :
Tidak ada komentar:
Posting Komentar