Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import java.util.logging.Handler;
- import javax.swing.*;
- // Adapter classes is for implemetning a class but overriding only the methods you need
- public class Gui extends JFrame{
- // Variables
- private String details;
- private JLabel statusbar;
- // Constructor
- public Gui(){
- super("JFrame's title");
- statusbar = new JLabel("This is default");
- add(statusbar, BorderLayout.SOUTH);
- addMouseListener(new Mouseclass());
- }
- // New class
- private class Mouseclass extends MouseAdapter{
- // I am allowed to override whatever I want
- public void mouseClicked(MouseEvent event){
- details = String.format("You clicked at %d %d", event.getX(), event.getY());
- details += String.format(" --- Clicks counter = %d", event.getClickCount());
- if(event.isMetaDown()){
- // Right mouse button is the meta key
- details += " --- With right mouse button";
- }
- else if(event.isAltDown()){
- details += " --- With center mouse button";
- }
- else{
- details += " --- With left mouse button";
- }
- statusbar.setText(details);
- }
- }
- // Main Function
- public static void main(String[] args){
- Gui gui = new Gui();
- gui.setDefaultCloseOperation(EXIT_ON_CLOSE);
- gui.setSize(600, 600);
- gui.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement