Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package app8;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import javax.swing.JPanel;
- public class DrawPanel extends JPanel implements MouseListener{
- public DrawPanel(){
- // подключаем обработчик событий для мыши
- addMouseListener(this);
- }
- //
- public void paintComponent(Graphics g){
- super.paintComponent(g);
- // color
- g.setColor(Color.red);
- // draw objects
- }
- @Override
- public void mouseClicked(MouseEvent e) {
- }
- @Override
- public void mousePressed(MouseEvent e) {
- //
- System.out.println("mousePressed>>");
- //(x,y)
- System.out.println("mousePressed.X=" + e.getX());
- System.out.println("mousePressed.Y=" + e.getY());
- }
- @Override
- public void mouseReleased(MouseEvent e) {
- }
- @Override
- public void mouseEntered(MouseEvent e) {
- }
- @Override
- public void mouseExited(MouseEvent e) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement