Results 1 to 3 of 3
  1. #1
    rstepler is offline Member
    Join Date
    Jul 2008
    Posts
    6
    Rep Power
    0

    Default Using Piccolo for Drawing

    I am using piccolo to create a drawing. I want to place the canvas (DrawCanvas) into a JPanel (SimulationPanel). The canvas's drawings are not appearing. I have posted my code below. Are there any suggestions? Thanks for your help.
    Java Code:
    public class CohortGui extends JFrame {
    	public CohortGui () {
    		super("Simulation");
    		setSize(1400,850);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		Thread runner;
    	// GUI menu
    		JMenu fileMenu = new JMenu("File");
    		JMenu simulationMenu = new JMenu("Simulation");
    		JMenu optionMenu = new JMenu("Option");
    		JMenu aboutMenu = new JMenu("About");
     
    		JMenuBar menuBar = new JMenuBar();
    			menuBar.add(fileMenu);
    			menuBar.add(simulationMenu);
    			menuBar.add(optionMenu);
    			menuBar.add(aboutMenu);
    		setJMenuBar(menuBar);
    	// Create DrawCanvas
    		DrawCanvas drawArea = new DrawCanvas();	
    	//Create simulationPanel
    		SimulationPanel sp = new SimulationPanel();
    		sp.setBackground(Color.white);
    		sp.add(drawArea); 
    		add(sp);
    
    
    
    ..........
    
    
    class DrawCanvas extends PCanvas {
    	public DrawCanvas(){
    		PLayer layer = new PLayer(); 
    		PCamera camera = new PCamera();
    		layer.addCamera(camera); 
    		//Create Lines
    		LineOne one = new LineOne();
    		LineTwo two = new LineTwo();
    		LineThree three = new LineThree();	
    		PLine test = new PLine();
    		test.setBounds(100,200,200,400);
    		
    		PImage ngo = new PImage("C:/Users/Renee/Desktop/toolbarButtonGraphics/INET_Earth_Clear.png");
    		ngo.setBounds(390, 75, getAlignmentX(), getAlignmentY());
    		layer.addChild(ngo);
    		PImage ngo2 = new PImage("C:/Users/Renee/Desktop/toolbarButtonGraphics/INET_Earth_Clear.png");
    		ngo2.setBounds(110,300,getAlignmentX(), getAlignmentY());
    		layer.addChild(ngo2);
    		PImage ngo3 = new PImage("C:/Users/Renee/Desktop/toolbarButtonGraphics/INET_Earth_Clear.png");
    		ngo3.setBounds(730,300, getAlignmentX(), getAlignmentY()); 
    		layer.addChild(ngo3); 
    		
    		layer.setPaint(Color.BLACK);
    		layer.addChild(one);
    		layer.addChild(two);
    		layer.addChild(three);
    		layer.addChild(test); 		
    		
    	}
    }
    class SimulationPanel extends JPanel {
    	public SimulationPanel () {
    		setLayout(null); 
    		JLabel testLabel= new JLabel("Test Label");
    		add(testLabel); 
    		
    		
    	}
    }

  2. #2
    Scott Izu is offline Member
    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Default Re: Using Piccolo for Drawing

    PCanvas can only be added to a JFrame. However, you can fake it as mentioned in: How to Fake Adding Piccolo’s PCanvas to a JPanel | scottizu

    There are two steps:
    1. Add PCanvas to top level JFrame
    2. Change the PCanvas bounds to match the JPanel

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    6

    Default Re: Using Piccolo for Drawing

    You're five years late!
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. Demonstration of drawing an Arc in SWT
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 06-28-2008, 09:24 PM
  2. Help with 2-D Drawing
    By Deathmonger in forum New To Java
    Replies: 4
    Last Post: 06-18-2008, 02:23 AM
  3. Drawing on aJPanel
    By Djangolo in forum AWT / Swing
    Replies: 1
    Last Post: 02-17-2008, 01:01 AM
  4. New: Want to understand Drawing...
    By diRisig in forum New To Java
    Replies: 1
    Last Post: 02-05-2008, 08:13 AM
  5. Help with drawing strings!
    By JavaInLove in forum AWT / Swing
    Replies: 1
    Last Post: 02-05-2008, 03:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •