Advertisement
sergAccount

Untitled

Dec 6th, 2020
1,024
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package app8;
  7.  
  8. import java.awt.Color;
  9. import java.awt.Graphics;
  10. import java.awt.event.MouseEvent;
  11. import java.awt.event.MouseListener;
  12. import javax.swing.JPanel;
  13.  
  14. public class DrawPanel extends JPanel implements MouseListener{
  15.    
  16.     public DrawPanel(){
  17.         // подключаем обработчик событий для мыши        
  18.         addMouseListener(this);
  19.     }
  20.     //
  21.     public void paintComponent(Graphics g){
  22.         super.paintComponent(g);
  23.         // color
  24.         g.setColor(Color.red);
  25.         // draw objects
  26.     }  
  27.     @Override
  28.     public void mouseClicked(MouseEvent e) {
  29.     }
  30.     @Override
  31.     public void mousePressed(MouseEvent e) {
  32.         //
  33.         System.out.println("mousePressed>>");
  34.         //(x,y)
  35.         System.out.println("mousePressed.X=" + e.getX());
  36.         System.out.println("mousePressed.Y=" + e.getY());
  37.     }
  38.     @Override
  39.     public void mouseReleased(MouseEvent e) {
  40.     }
  41.     @Override
  42.     public void mouseEntered(MouseEvent e) {
  43.     }
  44.     @Override
  45.     public void mouseExited(MouseEvent e) {
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement