Brovahkiin501's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Members
Active Posts:
48 (0.07 per day)
Joined:
01-October 12
Profile Views:
651
Last Active:
User is offline Jul 17 2014 04:11 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   Brovahkiin501 has not set their status

Posts I've Made

  1. In Topic: NullPointerException in Java Program

    Posted 10 Apr 2013

    I understand that. I have taken out the try/catch block. But I still do not understand how to fix my problem and I would really appreciate it if you could help me out. I don't know where I would have a null object.
  2. In Topic: NullPointerException in Java Program

    Posted 9 Apr 2013

    Yes, the error is at line 565 in what I posted. Here is the error code I am getting:

    Point of InterestException in thread "AWT-EventQueue-0" 
    java.lang.NullPointerException
    	at MapApp2.updateCustomComponent(MapApp2.java:564)
    	at MapApp2.access$0(MapApp2.java:553)
    	at MapApp2$RtsItemListener.actionPerformed(MapApp2.java:133)
    	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    	at javax.swing.JToggleButton$ToggleButtonModel.setPressed(JToggleButton.java:308)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    	at java.awt.Component.processMouseEvent(Component.java:6505)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
    	at java.awt.Component.processEvent(Component.java:6270)
    	at java.awt.Container.processEvent(Container.java:2229)
    	at java.awt.Component.dispatchEventImpl(Component.java:4861)
    	at java.awt.Container.dispatchEventImpl(Container.java:2287)
    	at java.awt.Component.dispatchEvent(Component.java:4687)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    	at java.awt.Container.dispatchEventImpl(Container.java:2273)
    	at java.awt.window.dispatchEventImpl(window.java:2719)
    	at java.awt.Component.dispatchEvent(Component.java:4687)
    	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
    	at java.awt.EventQueue.access$200(EventQueue.java:103)
    	at java.awt.EventQueue$3.run(EventQueue.java:682)
    	at java.awt.EventQueue$3.run(EventQueue.java:680)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    	at java.awt.EventQueue$4.run(EventQueue.java:696)
    	at java.awt.EventQueue$4.run(EventQueue.java:694)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
    
    
  3. In Topic: Java drawImage Method NumberFormatException

    Posted 28 Mar 2013

    Yeah, sorry about the indentation. It is indented but I copied it from a text file, and when I did that it got rid of the indentations and I didn't realize. And okay so how do I implement the drawImage method in a paintComponent() method? And also, how do I then get my image from the paintComponent() method to my doAction() method? Thank you very much for your help!
  4. In Topic: Java drawImage Method NumberFormatException

    Posted 28 Mar 2013

    I am sorry. I didn't want to paste the whole code as it is rather lengthy. So the user will be inputting the x-coordinate and y-coordinate and then I need to use those inputted values as the x and y values of my drawImage method. They will be inputting int numbers.
  5. In Topic: Store Int From TextField and Use In drawImage Method

    Posted 28 Mar 2013

    I am trying to use the integers inputted by the user in a JTextField in the drawImage method. We have to use the drawImage method for this part of the project. Here is the error I am getting when I try to run the code above,
    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
    


    and here are the other relevant programs you will need to run the app.

    BusStop
    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.ArrayList;
    
    /** Class that represents a BusStop on a 2D map */
    public class BusStop extends Location
    {
    	/** Stores a list of lines that stop at this busstop */
    	protected ArrayList<Line> lines;
    
    	/** Initializes lines to an empty list */
    	public BusStop()
    	{
    		lines = new ArrayList<Line>();     
    	}
    
    
    	/** Updates name, x, and y and initializes lines to an empty list */ 
    	public BusStop(String name, int x, int y)
    	{
    		super(name, x, y);
    		lines = new ArrayList<Line>();
    	}
    
    	/** Updates name, x, and y and initializes lines with numLines Line objects in array lines */ 
    	public BusStop(String name, int x, int y, Line[] lines, int numLines)
    	{
    		super(name, x, y);
    		this.lines = new ArrayList<Line>();
    		for(int i=0; i<numLines; i++)
    			this.lines.add(lines[i]);
    	}
    
    	/** Adds line l to lines */
    	public void addLine(Line l)
    	{
    		if (!lines.contains(l))
    			lines.add(l);
    	} 
    
    	/** Prints the info of the lines that stop at this busstop 
    	 * @param out */
    	public void printLineInfo(OutputStream o) throws IOException
    	{
    		super.printInfo();
    		System.out.println("Following lines stop at this bus stop");
    		for(int i=0; i<lines.size(); i++)
    			System.out.print(lines.get(i) + ((i == lines.size()-1) ? "\n" : ","));
    
    	}
    	
    	public java.lang.String getLineInfo() {
    		return name;
    	}
    
    }
    
    


    InvalidTimeException

    public class InvalidTimeException extends Exception {
    
    	public InvalidTimeException() {
    	}
    
    	public InvalidTimeException(String str) {
    		super(str);
    	}
    
    }
    
    


    IOUtil

    import java.util.Scanner;
    import java.io.File;
    import java.io.IOException;
    import java.io.ByteArrayOutputStream;
    import java.io.PrintWriter;
    import java.util.HashMap;
    import java.util.Collection;
    
    public class IOUtil {
    
    	static HashMap<String, BusStop> stops = new HashMap();
    	static HashMap<String, Line> lines = new HashMap();
    
    
    	public static java.util.ArrayList<java.lang.Object> readBusstopAndLineInfo(java.lang.String fileNAme) throws java.lang.Exception {
    		ByteArrayOutputStream outputString = new ByteArrayOutputStream();
    		PrintWriter output = new PrintWriter(outputString, true);
    
    		output.printf("\t%20s\n", "BUS STOPS");
    		Collection<BusStop> stopList = stops.values();
    		for (BusStop bs: stopList)
    			output.printf("\t%20s\n", bs);
    
    		output.printf("\t%20s\n","LINES");        
    		Collection<Line> lineList = lines.values();
    		for(Line e: lineList)
    			output.printf("\t%20s\n", e); 
    
    		return null;
    	}
    
    	public static void main(String[] args) {
    		try {
    			Scanner input = new Scanner(new File(args[0]));
    			input.useDelimiter("[[]=<>,\\s]");
    			if (!input.hasNext("busstops"))
    				throw new Exception("Expecting bus stops");
    			input.next();
    			while (!input.hasNext("route")) {
    				String BusstopName1 = input.next();
    				int x1 = input.nextInt();
    				int y1 = input.nextInt();
    				stops.put(BusstopName1, new BusStop(BusstopName1, x1, y1));
    			}
    			input.next();
    			while(input.hasNext()) {
    				String BusstopName1_1 = input.next();
    				int duration1_1 = input.nextInt();
    				lines.put(BusstopName1_1, new Line(BusstopName1_1, null, null, null, null, duration1_1));
    			}
    			System.out.print(readBusstopAndLineInfo("SCHEDULE"));
    		}
    		catch(IOException e) {
    			System.out.println(e);
    		}
    		catch(InvalidTimeException e) {
    			System.out.println(e);
    		}
    		catch(Exception e) {
    			System.out.println(e);
    		}
    	}
    }
    


    Line

    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.ArrayList;
    
    /** Class that represents a bus line */
    public class Line
    {
    	/** Line name */
    	protected String name;
    
    	/** Departure point */
    	protected Location departure;
    	/** Destination point */
    	protected Location destination;
    	/** List of bus stops that this lines stops at */
    	protected ArrayList<BusStop> route;
    	/** List of durations that show the amount of time it takes the bus 
    	 * to come from the previous Time Point type of bus stop to this one 
    	 */
    	protected ArrayList<Integer> timePoints;
    	/** The start time of this line */
    	protected Time first;
    	/** No service after this time */
    	protected Time last;
    	/** Period of buses that serve this line */
    	protected int period;
    
    
    	public Line() {}
    
    	/** Initializes the fields with the parameter values and initializes route and timePoints to empty lists */
    	public Line(String name, Location departure, Location destination, Time first, Time last, int period)
    	{
    		this.name = name;
    		this.departure = departure;
    		this.destination = destination; 
    		this.first = first;
    		this.last = last;
    		this.period = period;
    		route = new ArrayList<BusStop>();
    		timePoints = new ArrayList<Integer>();
    	}
    
    
    	/** Adds bus stop @param bs to the route list and adds @param durationFromPreviousTimePoint 
    	 * iff bs is a TimePoint object 
    	 * Also adds this line to lines list of bus stop bs 
    	 */
    	public void addNextBusStop(BusStop bs, int durationFromPreviousTimePoint)
    	{
    		if (!route.contains(bs))
    		{
    			route.add(bs);
    			bs.addLine(this);
    			if (bs instanceof TimePoint)
    				timePoints.add(durationFromPreviousTimePoint);     
    		}      
    	}
    
    	/** Prints the schedule of this line by explicitly showing the time point type of bus stops 
    	 * @param out */
    	public void printSchedule(OutputStream o) throws IOException
    	{
    		if (timePoints.size() == 0) return;
    
    		BusStop[] tp = new BusStop[timePoints.size()];
    		System.out.println("SCHEDULE FOR LINE " + name);
    		for(int i=0, j=0; i < route.size(); i++)
    		{
    			BusStop bs = route.get(i);
    			if (bs instanceof TimePoint)
    			{
    				tp[j++] = bs;
    				System.out.printf("%20s",bs.getName());
    			}   
    		}   
    		System.out.println();
    
    		Time next = first;
    		while (next.compareTo(last) != 1)
    		{
    			Time nextTimePoint = next.clone();
    			for(int i=0; i < tp.length; i++)
    			{
    				nextTimePoint = nextTimePoint.advanceMinutes(timePoints.get(i));
    				System.out.printf("%20s",nextTimePoint);
    
    			}   
    			System.out.println();
    			next = next.advanceMinutes(period);
    		}
    		System.out.println(); 
    	}
    	
    	public java.lang.String getSchedule() {
    		return name;
    	}
    
    	public void printRoute(OutputStream o) throws IOException
    	{
    		System.out.println("ROUTE FOR LINE " + name);
    		int numStops = route.size();
    		for(int i=0; i < numStops; i++)
    			System.out.print(route.get(i).getName() + ((i == numStops -1) ? "\n" : ", "));           
    	}
    	
    	public java.lang.String getRoute() {
    		return name;
    	}
    
    	public String toString()
    	{
    		return name;
    	}  
    }
    
    


    Location

    import java.awt.Image;
    import java.awt.image.ImageObserver;
    
    import javax.swing.JTextField;
    
    
    
    
    /** Class that represents a location on a 2D map */
    public class Location 
    {
    	protected int x;
    	protected int y;
    	protected String name;
    
    
    	/** Set x and y to 0 and name to empty String */
    	public Location()
    	{
    		x = 0;
    		y = 0;
    		name = "";
    	}
    
    	public Location(String name, int x, int y)
    	{
    		this.name = name;
    		this.x = x;
    		this.y = y;
    	}
    
    	public String getName() { return name; }
    
    	public void setName(String name) { this.name = name; }
    
    	public int getX() { return x; }
    
    	public void setX(int x) { this.x = x; } 
    
    	public int getY() { return y; }
    
    	public void setY(int y) { this.y = y; }
    
    	/*
      public double distance(Location other)
      {
         double xdiff = this.x - other.x;
         double ydiff = this.y - other.y;
         return Math.sqrt(xdiff*xdiff + ydiff*ydiff);
      }*/
    	public void move(int newX, int newY)
        {
            x = newX;
            y = newY; 
        }
    	
    
    	/** Returns the String "name at (x,y)" */
    	public String toString()
    	{
    		return name + " at (" + x +"," + y + ")"; 
    	}
    
    	/** Prints "name at (x,y)" */
    	public void printInfo()
    	{
    		System.out.println(name + " at (" + x +"," + y + ")");
    	}
    
    }
    
    


    Time

    /** 24-Hour Time */
    public class Time {
    
    	private int hours;  
    	private int minutes;
    
    	/** Sets time to 0:00 (12 midnight)*/
    	public Time() { hours = 0; minutes = 0;}
    
    	/** Initializes this to the given time */
    	public Time(int hours, int minutes) { this.hours = hours; this.minutes = minutes;}
    
    	/** Set this to the given time */           
    	public void set(int hours, int minutes) { this.hours = hours; this.minutes = minutes;}
    
    	/** Get the hour */              
    	public int getHours() { return hours; }
    
    	/** Get the minutes */               
    	public int getMinutes() { return minutes; }
    
    	/** Return a Time object that is minutes ahead of this time */
    	public Time advanceMinutes(int minutes) 
    	{ 
    		return new Time((this.hours + (this.minutes + minutes)/60) % 24, (this.minutes + minutes) % 60);         
    	}
    
    	public boolean equals(Time other)
    	{
    		return (other.hours == hours && other.minutes == minutes);    
    	}
    
    	public int compareTo(Time other)
    	{
    		if (equals(other))
    			return 0;
    		else {
    			if (hours < other.hours || (hours == other.hours && minutes < other.minutes))
    				return -1;
    			else return 1;    
    		}   
    	}
    
    	public Time clone()
    	{
    		return new Time(hours,minutes);
    	}                     
    
    	public String toString() { return (hours < 10 ? "0" : "") + hours + ":" + (minutes < 10 ? "0" : "") + minutes;}
    }
    
    
    


    TimePoint

    /** Class that represents a bus stop that is associated with a time point in the line schedule */
    public class TimePoint extends BusStop 
    {
    
    
    	public TimePoint()
    	{     
    	}
    
    	/** Initializes name, x, and y using the parameters by calling super*/ 
    	public TimePoint(String name, int x, int y)
    	{
    		super(name, x, y);
    	}
    
    	/** Initializes name, x, and y, and lines using the parameters by calling super*/ 
    	public TimePoint(String name, int x, int y, Line[] lines, int numLines)
    	{
    		super(name, x, y, lines, numLines);
    	}
    
    
    }
    
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

Brovahkiin501 hasn't added any friends yet.

Comments

Brovahkiin501 has no profile comments yet. Why not say hello?