package studienarbeit; import java.awt.*; import javax.swing.*; public class N_Vertex extends JPanel { protected void paintComponent( Graphics g ) { //VertexDrawer.drawThickLine( 1, 1, 100, 100, 5, g); VertexDrawer.drawThickLine( 30, 30, 200, 200, 20, g); } public static void main( String[] args ) { JFrame f = new JFrame(); f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); f.add( new N_Vertex() ); f.setSize( 400, 400 ); f.setVisible( true ); } } class VertexDrawer { public static void drawThickLine( int x, int y, int x2, int y2, int thickness, Graphics g ) { int b = Math.round( thickness /2), deltax, deltay; double angle; angle = Math.atan( (double)((y2-y)/(x2-x)) ); deltay = (int)Math.round( (Math.cos(angle)*b) ); deltax = (int)Math.round( (Math.sin(angle)*b) ); Polygon p = new Polygon(); p.addPoint( x-deltax, y+deltay ); p.addPoint( x+deltax, y-deltay ); p.addPoint( x2+deltax, y2-deltay ); p.addPoint( x2-deltax, y2+deltay ); g.fillPolygon( p ); } }