Java help please
The file contains information to draw a shape, for example:
rectangle 20 20 70 70 red
oval 30 50 60 70 blue
etc..
where the numbers are coordinates on an applet to draw the starting corner points.
I need it read the first line and store the variables so that i can then draw the shapes when i run it as an applet.
This isn't a complicated program but i'm having difficulty reading from a file and using the info respectively to draw the appropriate shapes. I need it to read from any similar file too so it needs to be able to do that.
Its basically a shape drawer program.
My code so far...(bad i know but i'm learning)
import java.io.*;
import java.awt.*;
import java.awt.Graphics;
import javax.swing.JApplet;
import java.util.*;
public class Program_2 extends JApplet
{
public void init()
{
Scanner inFile = new Scanner ( new FileReader("notsosmileyface.txt"));
{
String shape = inFile.next();
int x = inFile.nextInt();
int y = inFile.nextInt();
int width = inFile.nextInt();
int height = inFile.nextInt();
int secx = inFile.nextInt();
int secy = inFile.nextInt();
String color = inFile.next();
}
}
public void paint( Graphics g )
{
try
{
readInputFile(g); //unsure how to adjust this to read the file.
int numLines = null;
while (( numLines = inFile.readLine()) != null);
if (color.equals(black))
{
g.setColor(Color.black);
}
else if (color.equals(blue))
{
g.setColor(Color.blue);
}
else if (color.equals(cyan))
{
g.setColor(Color.cyan);
}
else if (color.equals(darkGray))
{
g.setColor(Color.darkGray);
}
else if (color.eqauls(gray))
{
g.setColor(Color.gray);
}
else if (color.equals(green))
{
g.setColor(Color.green);
}
else if (color.equals(lightGray))
{
g.setColor(Color.lightGray);
}
else if (color.equals(magenta))
{
g.setColor(Color.magenta);
}
else if (color.equals(orange))
{
g.setColor(Color.orange);
}
else if (color.equals(pink))
{
g.setColor(Color.pink);
}
else if (color.equals(red))
{
g.setColor(Color.red);
}
else if (color.equals(white))
{
g.setColor(Color.white);
}
else
{
g.setColor(Color.yellow);
}
if ( shape.equals(rectangle))
{
g.fillRec(x,y,width,height);
}
else if (shape.equals(oval))
{
g.fillOval(x,y,width,height);
}
else if (shape.equals(arc))
{
g.fillArc(x,y,width,height,secx,secy);
}
else
{
g.drawLine(x,y,width,height);
}
}
}
catch (FileNotFoundException fnf )
{
System.out.println("That file was not found.");
}
public void readInputFile( Graphics g ) throws FileNotFoundException
{
inFile.close();
}
}
Any helpful tips from various people would be greatly appreciated.
I may be making this harder then it needs to be but it is difficult to read the file and use the information to draw for me. thanks.

