Posts

Showing posts from December 17, 2010

Draw arrow line example

Draw arrow line example - 
Its a complete example

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

public class Test
{
public static void main (String args[])
{
SwingUtilities.invokeLater ( new Runnable () {
Test arrows = new Test();


public void run () {
JFrame frame = new JFrame ( "Arrows" );

frame.add ( new JPanel() {
public void paintComponent ( Graphics g ) {
arrows.draw ( ( Graphics2D ) g, getWidth(), getHeight() );
}
}
, BorderLayout.CENTER );

frame.setSize ( 800, 400 );
frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
frame.setVisible ( true );
}
} );
}

interface Arrow {
void draw ( Graphics2D g );
}

Arrow[] arrows = { new LineArrow(), new CurvedArrow() };

void draw ( Graphics2D g, int width, int height )
{
g.setRenderingHint ( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );

g.setColor ( Color.WHITE );
g.fillRect ( 0, 0, width, height );

for ( Arrow arrow : arrows ) {
g.setColor ( Color.ORANGE );
g.fillRect ( 350, 20, 20, 2…

Recent Post

Recent Posts Widget