By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,408 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,408 IT Pros & Developers. It's quick & easy.

How do I read from a text file and translate that info to graphics?

P: 10
My program is supposed to render graphics from the attached file. I can get my program to read the file without issue. My problem lies in getting the file to convert into graphics. I'm not even sure where to begin on this one. To say I'm frustrated would be a major understatement at this point. Here is my code so far:

Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.util.*;
  3. import*;
  5. public class Project8 {
  6.     static Graphics g;
  7.     // Program to render the objects described in the model file
  8.     public static void main(String[] args) throws FileNotFoundException {
  9.         Scanner input= new Scanner(new File("sun.txt"));
  10.         DrawingPanel panel = new DrawingPanel(500, 500);
  11.         g = panel.getGraphics();
  12.         while (input.hasNextLine()) {
  13.             String text = input.nextLine();
  14.             renderCommand(text);
  15.         }        
  16.     }
  18.     // takes a String rendering command and renders the specified
  19.     // line, oval, or rectangle to the drawing panel
  20.     public static void renderCommand(String text) {
  21.         Scanner commandLine = new Scanner(text);
  22.         String command = commandLine.nextLine();
  23.         if (command.equals(text)) {
  24.             System.out.println(text);
  26.         }
  28.         // 
  30.     }
  33. }
Any help would be most appreciated. I have been all over google and my textbook trying to figure this out to no avail. The answer is probably staring me right in the face, but I'm at my wits end on this.
Attached Files
File Type: txt sun.txt (18.8 KB, 306 views)
Apr 13 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.