/*
 
  * @author 张德瑞
  */
  import java.awt.Color;
  import java.awt.Font;
  import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseMotionListener;
   
  import javax.swing.JFrame;
  import javax.swing.JPanel;
   
  public class Demo04 {
  private int x = 100;
  private int y = 250;
   
  public void ShowJframe() {
 
 
  final JPanel jpanel = new JPanel() {
  public void paint(Graphics g) {
  Graphics2D graphics = (Graphics2D) g;
  graphics.setColor(Color.white);
  graphics.fillRect(0, 0, 400, 500);
 
  graphics.setColor(Color.red);
 
  }
  };
  jpanel.addMouseMotionListener(new MouseMotionListener() {
   
  @Override
  public void mouseMoved(MouseEvent e) {
  }
   
  @Override
  public void mouseDragged(MouseEvent e) {
  x = e.getX();
  y = e.getY();
  jpanel.repaint();
   
  }
  });
  jframe.add(jpanel);
  jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  jframe.setBounds(200, 300, 400, 500);
  jframe.setVisible(true);
  }
   
  public static void main(String[] args) {
  new Demo04().ShowJframe();
  }
   
  }
   
  }

相关文章:

  • 2021-12-05
  • 2022-01-18
  • 2022-01-07
  • 2021-05-21
猜你喜欢
  • 2022-02-23
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
  • 2021-07-05
  • 2021-07-24
相关资源
相似解决方案