Napisano: 23 Jan 2014 17:28
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.QuadCurve2D;
import javax.swing.*;
import javax.swing.border.*;
class Main extends JFrame {
private int tool = 1;
int currentX, currentY;
QuadCurve2D q = new QuadCurve2D.Float();
Graphics2D g2d;
public Main() {
initComponents();
}
private void initComponents()
{
jPanel2 = new Panel2();
q.setCurve(1, 2, 200, 200, 100, 200);
jPanel2.setBackground(new java.awt.Color(255, 255, 255));
jPanel2.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
jPanel2.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent evt) {
jPanel2MouseDragged(evt);
}
});
this.setContentPane(jPanel2);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
}
private void jPanel2MouseDragged(MouseEvent evt) {
if (tool == 1) {
currentX = evt.getX();
currentY = evt.getY();
q.setCurve(1, 2, currentX, currentY, 100, 200);
jPanel2.repaint();
}
}
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new Main().setVisible(true);
}
});
}
private JPanel jPanel2;
class Panel2 extends JPanel {
Panel2() {setPreferredSize(new Dimension(420,420));}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.draw(q);
}
}
}
Imam ovaj kod. Kako da dobijem koordinate svih tacaka, posto zelim da napravim neku igru u kojoj se neki objekat (cikica neki Ili mozda neki krug) krece po toj pravoj?
Dopuna: 28 Jan 2014 15:18
Still waiting.
|