combining shapes
was wondering how to combine two shapes or a shape and a line so that they can become one shape
any ideas?
polygon2 =new Polygon();
polygon2.addPoint(310, 310);
polygon2.addPoint(315, 350);
polygon2.addPoint(285, 350);
// combine with a line of certian lenght
[367 byte] By [
rossocka] at [2007-11-26 22:50:40]

# 3
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class SmallTest extends JPanel {
GeneralPath path;
Point p = new Point();
AffineTransform at = new AffineTransform();
int ds = 3;
public SmallTest() {
Polygon polygon2 = new Polygon();
polygon2.addPoint(310, 310);
polygon2.addPoint(315, 350);
polygon2.addPoint(285, 350);
Line2D.Double line = new Line2D.Double(265,350,335,350);
path = new GeneralPath(polygon2);
boolean connect = false;
path.append(line, connect);
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.draw(at.createTransformedShape(path));
}
public void addNotify() {
super.addNotify();
start();
}
private void start() {
Thread thread = new Thread(new Runnable() {
public void run() {
do {
try {
Thread.sleep(75);
} catch(InterruptedException e) {
break;
}
} while(advance());
}
});
thread.setPriority(Thread.NORM_PRIORITY);
thread.start();
}
private boolean advance() {
p.setLocation(p.x-ds, p.y-ds);
Rectangle r = path.getBounds();
at.setToTranslation(p.x, p.y);
Point2D origin = at.transform(r.getLocation(), null);
repaint();
return origin.getX() > 0 && origin.getY() > 0;
}
public static void main(String[] args) {
SmallTest test = new SmallTest();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(test);
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
}