This time add two buttons to your applet, one to read the data from the file into the linked list, and the other to display the data in the TextArea. When your applet opens, the TextArea should be there, but empty. When the read button is clicked, the data will be read in. Then when the display button is clicked, it will be displayed in the TextArea. See the example below.
import java.io.*;
import java.text.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
/* This applet displays a TextArea and two buttons. When the first button is clicked, the order data is read in from a file. When the second one is clicked, the data in the list is displayed in the TextArea. */
public class OrderButtons extends Applet
{
private Panel panel;
private TextArea area;
private OrderList list;
private Button read, display;
public void init ()
{
panel = new
Panel ();
panel.setBackground
(Color.cyan);
read = new Button
("Read Orders");
read.addActionListener
(new ReadListener ());
panel.add (read);
display = new
Button ("Display Order");
display.addActionListener
(new DisplayListener ());
panel.add (display);
area = new TextArea
(10, 30);
panel.add (area);
add (panel);
list = new OrderList
();
} // method init
// An inner class that listens for the clicking
of the read button.
class ReadListener implements ActionListener
{
public void
actionPerformed (ActionEvent e) {list.readOrders ();}
} // class ReadListener
// An inner class that listens for the clicking
of the display button.
class DisplayListener implements ActionListener
{
public void
actionPerformed (ActionEvent e)
{
list.displayOrders (area);
list.displayTotalCost (area);
}
} // class DisplayListener
} // class OrderButtons
class OrderList
{
// This class is the same as the example used
in assignment 6.
} // class OrderList
class Order
{
// This class is also the same as in assignment
6.
} // class Order