package apples;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class gui2 extends JFrame {
private JPanel mousepanel;
private JLabel statusbar;
public gui2 () {
super("title");
mousepanel.setBackground(Color.WHITE);
add(mousepanel,BorderLayout.CENTER);
statusbar = new JLabel("dfault");
add(statusbar, BorderLayout.SOUTH);
Handlerclass handler = new Handlerclass();
mousepanel.addMouseListener(handler);
mousepanel.addMouseMotionListener(handler);
}
private class HandlerClass implements MouseListener, MouseMotionListener {
public void mouseClicked (MouseEvent event) {
statusbar.setText(String.format("Clicked at %d,%d",event.getX()));
}
public void mousePressed (MouseEvent event) {
statusbar.setText("you pressed down the mouse");
}
public void mouseReleased (MouseEvent event) {
statusbar.setText("you released the button");
}
public void mouseEntered(MouseEvent event) {
statusbar.setText("you entered the area");
mousepanel.setBackground(Color.RED);
}
public void mourseExisted(MouseEvent event) {
statusbar.setText("the mouse had left the window");
}
};
}
Comments
Post a Comment