So I have the code below. The whole program just reads from a text file and prints certain characters if it detects specific characters from the text file (in this case I just made it mimics what the text file has).
My text file contains this:
.........www...
bbb..........ww
...bb....ww....
The program would print out exactly that.
The next step I'm trying to figure out now is how to make the program print out objects (circle, square, dot, etc.) instead of just letters? Like if it detects a dot from the text file, print a small circle.
How would I go about implementing this? I tried the paint method from Graphics2D but can't invoke/call it since that is call automatically. I'm very new to java graphics.
Any help would be greatly appreciated. Thanks.
import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class Read
{
public static void main(String[] args)
{
try
{
char currentChar = '.';
FileInputStream inputStream = new FileInputStream("test.txt");
while (currentChar != (char)-1 )
{
currentChar = (char)inputStream.read(); // Cast to a char
if (currentChar == 'b')
{
System.out.print("b");
}
else if (currentChar == 'w')
{
System.out.print("w");
}
else if (currentChar == '.')
{
System.out.print(".");
}
else if (currentChar == ' ')
{
System.out.print("\n");
}
}
}
catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}