Advertisement
Guest User

Untitled

a guest
May 16th, 2012
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.image.BufferedImage;
  3. import javax.swing.*;
  4. public class MyCanvas extends JPanel
  5. {
  6.    
  7.     public MyCanvas() {
  8.        
  9.     }
  10.     public void paintComponent(Graphics g) {
  11.         super.paintComponent(g);
  12.     }
  13.    
  14.     public static void main(String[] args)
  15.     {
  16.         int vertexes = 0;
  17.         // Change this next part later to be dynamic.
  18.         vertexes = 10;
  19.         int canvasSize = vertexes * vertexes;
  20.        
  21.         JFrame frame = new JFrame();
  22.         JLabel label = new JLabel();
  23.         BufferedImage bImage = new BufferedImage(canvasSize, canvasSize, BufferedImage.TYPE_INT_ARGB);
  24.         Graphics2D g2d = bImage.createGraphics();
  25.         g2d.drawLine(50, 50, 300, 300);
  26.         ImageIcon iIcon = new ImageIcon(bImage);
  27.         label.setIcon(iIcon);
  28.         frame.add(label);
  29.         frame.setVisible(true);
  30.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31.         g2d = drawNode(1,1,g2d);
  32.         label.repaint();
  33.     }
  34.  
  35.     public static Graphics2D drawNode(int x, int y,Graphics2D g2d)
  36.     {
  37.             // Treat each location as a 10x10 block. If position 1,1 then go to (5,5) - If position 3,5 then go to (25, 45) eg: (x*10)-5, (y*10)-5
  38.             int xLoc = (x*10) - 5;
  39.             int yLoc = (y*10) - 5;
  40.             g2d.setColor(Color.white);
  41.             g2d.fillOval(xLoc, yLoc, 8, 8);
  42.             g2d.drawOval(xLoc, yLoc, 8, 8);
  43.             return g2d;
  44.     }
  45.     public static void drawArc(int x, int y, int xx, int yy)
  46.     {
  47.             int xLoc = (x*10) - 5;
  48.             int yLoc = (y*10) - 5;
  49.             int xxLoc = (xx*10) - 5;
  50.             int yyLoc = (yy*10) - 5;
  51.            // g.drawLine(xLoc, yLoc, xxLoc, yyLoc);
  52.     }
  53.        
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement