package gui; import java.awt.*; import java.awt.event.*; public class PaintFrame extends Frame { private static final long serialVersionUID = 1L; private int _x, _y, x, y; private boolean bps = false; public void paint(Graphics g) { if (bps) { Color c = g.getColor(); g.setColor(Color.RED); g.drawLine(_x, _y, x, y); g.setColor(c); } } public PaintFrame() { this.setBounds(230, 100, 600, 500); this.setTitle("画图"); this.setResizable(false); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); this.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { _x = e.getX(); _y = e.getY(); } public void mouseReleased(MouseEvent e) { bps = false; } }); this.addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent arg0) { bps = true; } public void mouseDragged(MouseEvent e) { x = e.getX(); y = e.getY(); PaintFrame.this.paint(PaintFrame.this.getGraphics()); _x = x; _y = y; } }); this.setVisible(true); } public static void main(String[] args) { new PaintFrame(); } }
JAVA画图
最新推荐文章于 2024-09-19 21:52:00 发布