AWT, Swing, JavaFX ne kullanıyorsunuz?
Hocam Swing.
Ben biraz uğraştım istediğim şekilde(basılı tutmak değil sadece sağ click ile bir noktayı sol click ile bir noktayı ayarlayabiliyorum) bir çizgi çizebiliyorum fare ile ama 2.bir çizgiyi çizdiğimde birinci kayboluyor . Bunun sağlanması için dizi kullanmam gerek .Ancak drawline komutunumu dizide kullanacağım bu yönde bir mantık yürütemedim.
Yazdığım kodları ekliyorum hocam.
public static void main(String[] args) {
BizimPencere x = new BizimPencere();
x.setSize(300, 200);
x.setVisible(true);
x.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public class BizimPencere extends JFrame implements MouseListener {
private int x1, y1, x2, y2;
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawLine(x1, y1, x2, y2);
}
public BizimPencere() {
addMouseListener(this);
x1 = 0;
y1 = 0;
x2 = 0;
y2 = 0;
}
public void mouseClicked(MouseEvent e) {
if (e.getButton() == e.BUTTON1) {
x1 = e.getX();
y1 = e.getY();
}
else if (e.getButton() == e.BUTTON3) {
x2 = e.getX();
y2 = e.getY();
}
repaint();
}