Ok, I'm having the hardest time writing this code for work. Any suggestions on how to get me going in the right direction on this code would be great!!!
Project:
I need to make uninstalled fonts available for viewing for my co-workers. Therefore, I'm to write a code that can do this from the intranet site. First, I compiled a list of fonts on excel, csv, and text (tab delimited). Then I started to write the code in an applet that can ask the user to type in a font. Then the program is to spit out font(s) that are included in the users request or "no font available".
I got halfway there and then I somehow backtracked to this horrible code. Can anyone help me or maybe give me strong solid advice or a better direction on this coding?
import java.applet.Applet;
import java.awt.Button;
import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.TextField;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class DuckShowFonts extends Applet {
String fileToRead = "fonts.csv";
String line;
String repeat_mindlessly = "";
String n;
String prHtml;
int i;
Graphics g;
ArrayList<String> data;
FileReader fr;
BufferedReader br;
StringBuffer strBuff;
TextField typedFont;
TextField typeface;
Button findTheFont;
Label qForFont;
public void init() {
setSize(800,200);
qForFont = new Label("What font are you looking for? ");
add(qForFont);
typedFont = new TextField(20);
add(typedFont);
g=getGraphics();
findTheFont = new Button("Find Font");
add(findTheFont);
prHtml = this.getParameter(fileToRead);
if (prHtml != null) fileToRead = new String(prHtml);
try {
retreiveFile();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void retreiveFile() throws IOException {
fr = new FileReader(fileToRead);
br = new BufferedReader(fr);
data = new ArrayList<String>();
//strBuff = new StringBuffer(); - do i need this too?
while((line = br.readLine()) != null){
data.add(line);
//strBuff.append(line + "\n"); - do i need this?
}
for (i=0; i<data.size(); i++) {
if (typedFont.equals(data.get(i))) {
System.out.print(typedFont);
}
else{
System.out.print("not in database");
}
}
//txtArea.append(strBuff.toString());
}
public boolean action(Event e,Object o)
{
n = typedFont.getText();
//repaint(); - should i use this?
return true;
}
public void paint(Graphics g){
g.setColor(Color.black);
g.drawString("Here are your choices "+n,10,100);
//update(g);
}
}