DrawLineCanvas.java
Dosyayı İndir
package com.godoro.samples.awt;
import java.awt.*;
import java.awt.event.*;
public class DrawLineCanvas extends Canvas
{
private int x1;
private int y1;
private int x2;
private int y2;
public DrawLineCanvas()
{
MouseAdapter mouse=new MouseAdapter(){
public void mousePressed(MouseEvent e){
x1 = e.getX();
y1 = e.getY();
}
};
addMouseListener(mouse);
MouseMotionAdapter motion = new MouseMotionAdapter(){
public void mouseDragged(MouseEvent e){
x2 = e.getX();
y2 = e.getY();
repaint();
}
};
addMouseMotionListener(motion);
}
public void paint(Graphics g){
g.drawLine(x1, y1, x2, y2);
}
public static void main(String[] args){
Frame frame = new Frame();
frame.setBounds(0, 0, 300, 300);
DrawLineCanvas canvas = new DrawLineCanvas();
frame.add(canvas);
frame.setVisible(true);
}
}
Dosyayı İndir