Package lec05.glab.eventmodel

Source Code of lec05.glab.eventmodel.MyApp

package lec05.glab.eventmodel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class MyApp {

  private JFrame frame;

  /**
   * Launch the application.
   */
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      public void run() {
        try {
          MyApp window = new MyApp();
          window.frame.setVisible(true);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    });
  }

  /**
   * Create the application.
   */
  public MyApp() {
    initialize();
  }

  /**
   * Initialize the contents of the frame.
   */
  private void initialize() {
    frame = new JFrame();
   
   
    frame.getContentPane().addMouseListener(new MouseListener() {
      @Override
      public void mouseClicked(MouseEvent e) {
       
        JOptionPane.showMessageDialog(null, e.getPoint());
      }

      @Override
      public void mousePressed(MouseEvent e) {
        // TODO Auto-generated method stub
       
      }

      @Override
      public void mouseReleased(MouseEvent e) {
        // TODO Auto-generated method stub
       
      }

      @Override
      public void mouseEntered(MouseEvent e) {
        // TODO Auto-generated method stub
       
      }

      @Override
      public void mouseExited(MouseEvent e) {
        // TODO Auto-generated method stub
       
      }
    });
    frame.getContentPane().addMouseMotionListener(new MouseMotionListener() {
      @Override
      public void mouseMoved(MouseEvent e) {
       
        System.out.println(e.getPoint());
      }

      @Override
      public void mouseDragged(MouseEvent e) {
        //do nothing
       
      }
    });
    frame.setBounds(100, 100, 450, 300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

}
TOP

Related Classes of lec05.glab.eventmodel.MyApp

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.