can an applet read from a file
ive been trying to do this code and cant get it to read can anybody plaese help
import java.awt.*;
import java.util.*;
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
public class Assessement2 extends JApplet implements ActionListener{
JLabel Title,Photo,Author,Topic,LQuote;
JComboBox TopicCombo,AuthorCombo;
JButton QuoteButton;
JTextArea QuoteArea;//various variables that i needed to complete the program
ArrayList theauthor = new ArrayList();
ArrayList thesubject = new ArrayList();
ArrayList Quote = new ArrayList();
public void init(){//this method is used to organise the interface
Container c =getContentPane();
c.setLayout(null);
Title=new JLabel("Quote Generator", JLabel.CENTER);
Title.setFont(new Font("Serif", Font.BOLD, 24));
Title.setForeground(Color.white);
Title.setBounds(0,5,350,30);
c.add(Title);
//Photo=new JLabel(candle.gif);
//private Image candle;
Author=new JLabel("Authors Name");
Author.setForeground(Color.white);
Author.setBounds(10,40,150,20);
c.add(Author);
//FileLoad();
AuthorCombo=new JComboBox();
AuthorCombo.setBounds(10,60,150,25);
c.add(AuthorCombo);
Topic=new JLabel("Topic Area");
Topic.setForeground(Color.white);
Topic.setBounds(190,40,150,25);
c.add(Topic);
TopicCombo=new JComboBox();
TopicCombo.setBounds(190,60,150,25);
c.add(TopicCombo);
LQuote=new JLabel("Quote", JLabel.CENTER);
LQuote.setForeground(Color.white);
LQuote.setBounds(0,100,350,25);
c.add(LQuote);
QuoteArea=new JTextArea();
QuoteArea.setBounds(30,130,290,130);
c.add(QuoteArea);
QuoteButton=new JButton("Press Here to Enter the Quote into the System");
QuoteButton.setBounds(2,270,348,30);
QuoteButton.setForeground(Color.white);
c.add(QuoteButton);
QuoteButton.addActionListener(this);
setBackground ( Color.black );
}
public void FileLoad() {
try {
// Open the file that stores my quotes
FileReader quoteStream = new FileReader ("Data.txt");
BufferedReader quoteIn = new BufferedReader (quoteStream);
String str, tmp;
boolean FQuote = false;
while ((str = quoteIn.readLine()) != null) {
Quote.add(str);
}
// Close the File
quoteIn.close();
} catch (IOException except) {
JOptionPane.showMessageDialog (null, "The File was not readable");
}
}
public void Randomise() {
int QuoteButton = (int)(Math.floor(Math.random()*(Quote.size()-1)+1));
DisplayQuote(QuoteButton);
}
public void DisplayQuote(int quoteIndex) {
TopicCombo.setSelectedIndex(quoteIndex+1);
AuthorCombo.setSelectedIndex(quoteIndex+1);
QuoteArea.setText ("");
String s=(String)theauthor.get(quoteIndex);
String st[]=s.split("#");
QuoteArea.append(st[2]);
}
private Object MakeObject(final String item) {
return new Object() { public String toString() { return item; } };
}
public void actionPerformed (ActionEvent e) {
if (e.getSource() == QuoteButton) {
Randomise();
} else if (e.getSource() == AuthorCombo) {
DisplayQuote(AuthorCombo.getSelectedIndex()-1);
} else if (e.getSource() == TopicCombo) {
DisplayQuote(TopicCombo.getSelectedIndex()-1);
}
}
}
|