Switch to full style
General Java code examples
Post a reply

draw General Path

Tue Nov 11, 2008 8:36 pm

draw General Path using java
java code
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
import java.util.Vector;

public class ShowGeneralPath extends JApplet {
Canvas1 canvas;

public static void main(String[] args) {
JFrame frame = new JFrame("Show General Paths");
ShowGeneralPath path = new ShowGeneralPath();
path.init();
frame.getContentPane().add(path);
frame.setSize(280, 250);
frame.show();
}
public void init() {
Container container = getContentPane();
JPanel panel = new JPanel();
canvas = new Canvas1();
container.add(canvas);
}
class Canvas1 extends Canvas {
Vector generalPath;

public Canvas1() {
setBackground(Color.white);
setSize(400, 200);
generalPath = new Vector();
GeneralPath path1, path2,path3;

path1 = new GeneralPath();
path1.moveTo(25, 35);
path1.lineTo(35, 50);
path1.lineTo(50, 20);
path1.lineTo(80, 30);
path1.curveTo(20, 100, 110, 60, 40, 100);
generalPath.addElement(path1);

path2 = new GeneralPath();
path2.moveTo(120, 20);
path2.lineTo(120, 80);
path2.lineTo(180, 20);
path2.lineTo(180, 80);
path2.closePath();
generalPath.addElement(path2);

path3 = new GeneralPath();
path3.moveTo(50, 120);
path3.lineTo(70, 180);
path3.lineTo(20, 140);
path3.lineTo(80, 140);
path3.lineTo(30, 180);
path3.closePath();
generalPath.addElement(path3);
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
for (int i = 0; i < generalPath.size(); i++) {
g2d.setPaint(Color.red);
g2d.draw((GeneralPath) generalPath.elementAt(i));
}
}
}
}



Attachments
path.gif
draw path .
path.gif (4.99 KiB) Viewed 11400 times

Post a reply
  Related Posts  to : draw General Path
 Java code to draw shortest path tree     -  
 c++ general programming     -  
 General Error: Style data     -  
 General call (Invoke) to method     -  
 get include path     -  
 Dijkstra ( Shortage Path )     -  
 Dijkstra ( Shortest Path )     -  
 get Folder path and size     -  
 shortest path algorithm java     -  
 return file path after encoded using UTF-8 from URL     -  

Topic Tags

Java Graphics