**This program is supposed to read data in from a file into an array list and everything compiles correctly so far but when i go to run the applet ProcessNovels it shows a blank window saying "Start: applet not initialized? Im not sure where the problem actually is i am a beginner programmer < SORRY SO LENGTHY > **
Heres my code for ProcessNovels
import java.awt.*;
import javax.swing.*;
import java.util.Scanner;
import java.io.*;
import java.io.IOException;
import java.awt.Color;
import java.awt.Font;
import javax.swing.ImageIcon;
import java.util.*;
/**
* Class ProcessNovels - program that reads noels from a file and displays them using an Applet
* *
* @author (wayne summers)
* @version (10/16/2011)
*/
public class ProcessNovels extends JApplet
{
final int NUMBEROFNOVELS = 5;
ImageIcon icon = new ImageIcon("queen-mary.png");
Novel novel1, novel2, novel3, novel4, novel5;
Font small, big;
Color gray;
private Scanner input;
ArrayList<Novel> novels = new ArrayList<Novel>();
/**
* Called by the browser or applet viewer to inform this JApplet that it
* has been loaded into the system. It is always called before the first
* time that the start method is called.
*/
public void init()
{
resize(800,800);
small = new Font("Serif", Font.PLAIN, 14);
big = new Font ("SansSerif", Font.BOLD + Font.ITALIC, 36);
gray = new Color (128, 128, 128);
getData();
}
/**
* parseLine method receives a line of text for a novel
* of the form title, author, date Published, and genre where each field is separated by a comma
* the line is parsed and a response is built and returned
*
* @parm line - line of text
* @return - Novel
*/
private static Novel parseLine(String line)
{
Scanner lineScanner;
String title;
String author;
int datePublished;
String genre;
Novel nov;
lineScanner = new Scanner(line);
lineScanner.useDelimiter(",");
title = lineScanner.next();
author = lineScanner.next();
datePublished = lineScanner.nextInt();
genre = lineScanner.next();
nov = new Novel (title, author, datePublished, genre);
return nov;
}
/**
* getData method reads lines of text for novels from a file and stores them into Novel objects
*
* @parm none
* @return - none
*/
//read file
public void getData()
{
try
{
try
{
FileReader in = new FileReader("novels.txt");
input = new Scanner(in).useDelimiter("\\s\\s");
}
catch( FileNotFoundException fileNotFound)
{
System.err.println( "Error opening file.");
System.exit(1);
}
while ( input.hasNextLine())
{
novels.add( new Novel(input.next(), input.next(), input.nextInt(), input.next() ));
for (Novel list : novels)
{
System.out.printf("%-10s%-48s$%5.2f\n", list.getTitle(), (list.getAuthor()+ ", "+ list.getDatePub()+ "g") + list.getGenre());
//System.out.println(item);
}
}
}
catch ( NoSuchElementException elementEx)
{
System.err.println( "Incorrect file format.");
System.exit(1);
}
catch ( IllegalStateException stateEx )
{
System.err.println( "Error reading from file.");
System.exit(1);
}
}
public void closeFile()
{
if (input != null)
input.close();
}
/**
* Paint method for applet.
*
* @param g the Graphics object for this applet
*/
public void paint(Graphics g)
{
double average;
g.setFont(big);
g.setColor(Color.DARK_GRAY);
g.drawString ("Victorian Reading List", 10, 40);
// displays novel in Applet
g.setFont(small);
g.setColor(Color.BLUE);
displayNovel( g, novel1, 20, 80);
displayNovel( g, novel2, 20, 120);
displayNovel( g, novel3, 20, 160);
displayNovel( g, novel4, 20, 200);
displayNovel( g, novel5, 20, 240);
g.setFont(big);
g.setColor(gray);
average = computeAverage();
g.drawString ("Average age of the novels is " + average + " years.", 10, 380);
//version displays an imageIcon on this "frame" at location (10, 450)
icon.paintIcon(this, g, 10, 450);
}
/**
* displayNovel method that displays an novel at a designated location.
*
* @param g the Graphics object for this applet
* @param novel novel
* @param x x coordinate of location to drawString
* @param y y coordinate of location to drawString
*/
public void displayNovel(Graphics g, Novel novel, int x, int y)
{
String response;
// build text to display on applet
response = novel.getTitle() + " written by " + novel.getAuthor() + ", published in "
+ novel.getDatePub() + ", is a " + novel.getGenre() + " book.";
g.drawString(response, x+20, y);
}
/**
* compute average age method.
*
* @returns avg average age of novels
*/
public double computeAverage()
{
int totalAge;
double averageAge;
totalAge = novel1.getAge() + novel2.getAge() + novel3.getAge() + novel4.getAge() + novel5.getAge();
averageAge = (double) totalAge / NUMBEROFNOVELS;
return averageAge;
}
}
**This is my Novel Class just incase anyone needed it as extra information.**
import java.util.*;
/**
* class Novel with title, author, date published and genre.
*
* @author (wsummers)
* @version (10/16/2012)
*/
public class Novel
{
// instance variables - replace the example below with your own
private String title;
private String author;
private int datePublished;
private String genre;
private final int TODAYSYEAR = 2012;
/**
* Constructor for objects of class Novel
*/
public Novel(String title, String author, int datePublished, String genre)
{
// initialise instance variables
this.title = title;
this.author = author;
this.datePublished = datePublished;
this.genre = genre;
}
/**
* getTitle - returns book title
*
* @return title
*/
public String getTitle()
{
return title;
}
/**
* setTitle - updates book title
*
* @param newTitle new value of book title
*/
public void setTitle(String newTitle)
{
title = newTitle;
}
/**
* getAuthor - returns book author
*
* @return author
*/
public String getAuthor()
{
return author;
}
/**
* setAuthor - updates book author
*
* @param newAuthor new value of book author
*/
public void setAuthor(String newAuthor)
{
author = newAuthor;
}
/**
* getDatePub - returns datePublished
*
* @return datePublished
*/
public int getDatePub()
{
return datePublished;
}
/**
* setDatePub - updates datePublished
*
* @param newDatePub new value of datePublished
*/
public void setDatePub(int newDatePub)
{
datePublished = newDatePub;
}
/**
* getGenre - returns book genre
*
* @return genre
*/
public String getGenre()
{
return genre;
}
/**
* setGenre - updates book genre
*
* @param newGenre new value of book genre
*/
public void setGenre(String newGenre)
{
genre = newGenre;
}
/**
* getAge - computes and returns book age usng the Calendar class
*
* @return age
*/
public int getAge()
{
int age;
Calendar cal;
int year;
cal = Calendar.getInstance(); // gets an instance of a Calendar
year = cal.get(Calendar.YEAR); // gets the year from the calendar
age = year - datePublished;
return age;
}
/**
* toString - returns contents of object
*
* @return result
*/
public String toString()
{
String result;
result = "title = \t" + title;
result = "author = \t" + author;
result = "datePublished = \t" + datePublished;
result += "\ngenre = \t" + genre;
return result;
}
}
Any Kind of help would be useful Thanks! this assignment is due tomorrow morning before 8am i'll be up until i can get it solved any help is urgently needed thank you so much!