Results 1 to 3 of 3
  1. #1
    Surgeant is offline Member
    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Default Trying to create a class using the ACM Graphics library

    Hi All,

    I am trying to create class name map that would display a map to the canvas. So far, the map class is only coded to print a line to a canvas. when I run the code the canvas appears, but there is no line. Can someone explain why this code is not working? I have two files one to test the map class and the other is the map class.

    test program

    Java Code:
    public class test {
    
    	public void run() {
    		
    		map obj = new map();
    		obj.drawMap();
    	}
    
    }
    map class

    Java Code:
    import acm.graphics.*;
    import acm.program.*;
    
    public class map extends GraphicsProgram{
    	
    	/**
    	 * 
    	 */
    	protected double mapSizeX, mapSizeY;
    	
    	public map(){
    		mapSizeX = 400.0;
    		mapSizeY = 400.0;
    	}
    	
    	public void drawMap(){
    		GLine leftVerticalLine = new GLine(10.0, 10.0, mapSizeX, mapSizeY);
    		add(leftVerticalLine);
    		
    	}
    
    }

  2. #2
    Surgeant is offline Member
    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Default Re: Trying to create a class using the ACM Graphics library

    Thanks jbarker12:). That was not the issue. There were 3 issue. First, I needed to extend the map library to GCompound. Second, I needed to extend the test class to Graphics program. Finally, in the test library inside the run method I had to add the map class. The code is listed below.

    Java Code:
    import acm.program.GraphicsProgram;
    
    public class test extends GraphicsProgram {
    	public map obj;
    
    	public void run(){
    		obj = new map();
    		obj.drawMap();
    		add(obj);
    	}
    	
    }

    Java Code:
    import acm.graphics.GCompound;
    import acm.graphics.GLine;
    
    public class map extends GCompound{
    	
    	/**
    	 * 
    	 */
    
    	protected int mapSizeX, mapSizeY;
    	
    
    	public map()
    	{
    		mapSizeX = 400;
    		mapSizeY = 400;
    	}
    	
    	public void drawMap()
    	{
    	    
    		GLine leftVerticalLine = new GLine(10, 10, 10, mapSizeY + 10);
    		add(leftVerticalLine);
    
    		
    	}
    	
    
    }

  3. #3
    jbarke12 is online now Member
    Join Date
    May 2013
    Location
    Charleston, South Carolina USA
    Posts
    82
    Rep Power
    0

    Default Re: Trying to create a class using the ACM Graphics library

    That makes sense. I haven't used ACM for years. I just remember when I was in school setVisible() was always an issue when something wasn't being added correctly

Similar Threads

  1. Replies: 10
    Last Post: 09-03-2012, 08:13 PM
  2. The Graphics Class
    By Everyman in forum New To Java
    Replies: 5
    Last Post: 02-10-2012, 04:38 PM
  3. How do you install and use a class library?
    By ConMan in forum New To Java
    Replies: 4
    Last Post: 06-07-2011, 09:39 AM
  4. How create big Graphics?
    By artemff in forum CLDC and MIDP
    Replies: 1
    Last Post: 01-01-2010, 11:20 PM
  5. How to create a directory using the library java.io
    By bachtoutou in forum New To Java
    Replies: 3
    Last Post: 05-23-2008, 10:08 PM

Posting Permissions

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