i am a newbie in java. i am working on an assignment in which i am reading commands from file and drawing the shapes on jpanel. the file is like
FRAME 200 100 // open a frame, note: parser must ignore any comments
COLOR 255 0 0 // set color to red
RECTANGLE 20 30 40 20 // draw a red rectangle
COLOR 128 128 128 // set color to gray
CIRCLE 100 50 25 // draw a gray circle
FRAME 100 100 // open a second frame
COLOR 0 0 255 // set color to blue
ELLIPSE 50 50 30 20 // draw a blue ellipse
COLOR 0 255 0 // set color to green
LINE 10 20 90 80 // draw a green line
i have written the following code.
JFrame frame = new JFrame("JFrame Source Demo");
frame.setTitle("Drawing Graphics in Frames");
frame.setBounds(100,50,500,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
///////////////////
File file = new File("Paint_instruction.txt");
// Get data from this file using a file reader.
FileReader fr = new FileReader(file);
// To store the contents read via File Reader
BufferedReader br = new BufferedReader(fr);
//writer to write in file
while((data = br.readLine()) != null)
{
/*String[] tokens = data.split("\\s{1,}");
for(int i=0;i<tokens.length;i++)
{System.out.println(tokens[i]);}*/
String []tokens = data.split("\\s{1,}");
if(tokens[0].equals("FRAME"))
{JFrame frame2 = new JFrame("JFrame Source Demo");
frame2.setBounds(0, 0, 40, 40);
frame2.setVisible(true);
}
else if(tokens[0].equals("RECTANGLE"))
{
//draw circle
}
else if(tokens[0].equals("CIRCLE"))
{
//draw circle
}
else if(tokens[0].equals("LINE"))
{
//draw Line
}
else if(tokens[0].equals("ELLIPSE"))
{
//draw ELLIPSE
}
i do not know how to use paint function to draw these shapes. I have tried to pass array to paint function. but it did not work. I have goggled it but did not find any appropriate help