私はベクトルグラフィックスエディタを作成していますし、正常にペイントブラシと今、私が何であるかを悩まRectange、楕円、線などのようないくつかの基本的な2D形状を作成しているが2Dでを使用して曲線ツールを作成し、私のJavaのベクターグラフィックスのためのスイングCurved LineまたはCurveツールを使用します。私はをのmousePressedし、各をmouseDragged上の第二の点を更新から原点を取得することにより、他の人が作成しました。ここでは、コードの一部です:はエディタ
public void mousePressed(MouseEvent e){
gfx.setColor(Tool.currentColor);
pos1 = e.getPoint(); //Get the First Point
}
public void mouseReleased(MouseEvent e){
if(!e.isAltDown() && !e.isMetaDown())
if(currentShape != null) shapeSet.add(currentShape);
currentShape = null;
}
public void mouseDragged(MouseEvent e){
if(e.isAltDown() || e.isMetaDown()) return;
//the mouse was dragged, so begin painting
pos2 = e.getPoint();
int ctool = Tool.currentTool;
if(ctool == Tool.LINE){
currentShape = new Line(pos1,pos2,Tool.currentColor,null);
}else if(ctool == Tool.ELLIPSE){
currentShape = new Ellipse(pos1,pos2,Tool.currentColor,null);
}else if(ctool == Tool.RECTANGLE){
currentShape = new Rectangle(pos1,pos2,Tool.currentColor,null);
}
this.repaint();
}
ラインは、楕円などのクラスは、彼らはただの点を取り、後で再描画でそれらを描く、非常に簡単です。一時currentShapeに格納された全ての形状はその後抽象クラス形状のArrayListのあるshapeSet、に付加されています。
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
gfx.setBackground(Color.WHITE);
gfx.clearRect(0, 0, img.getWidth(), img.getHeight());
for(int i=0; i< shapeSet.size(); i++){
shapeSet.get(i).draw(gfx);
}
if(currentShape != null){
currentShape.draw(gfx);
}
g.drawImage(img, 0, 0, null);
}
IMGはたBufferedImageで、GFXは、IMGのグラフィックです。
img = new BufferedImage(640,480,BufferedImage.TYPE_INT_RGB);
gfx = img.createGraphics(); //Graphics2D
は今、どのように正確に私はカーブツールを作成するに行きますか?
P.S Shape(Line、Ellipseなど)クラスのコードを希望する場合は、コメントして投稿します。
'gfx'何喜ば??? – mKorbel
私は自分の質問を編集し、それを述べました。 – ApprenticeHacker