I have broken down my GUI app into just the shell to see where I am going wrong. I am following the outline in my book and have used the set-up as written in my book but I can't get the first part of the code to compile. What am I doing wrong? When I try to compile, I get the following error: TSAssn5a.java:11: TSAssn5a is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
public class TSAssn5a extends JFrame implements ActionListener{
^
CODE
/*
TS NU Grades GUI Interface Assignment 5
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
//#1 Implement event proceesing
public class TSAssn5a extends JFrame implements ActionListener{
private JTextArea frameTextArea; //create a text area
private Container frameContainer; //for the content pane
private JScrollPane scrollForTextArea; //scroll bar
private BorderLayout frameLayout; //default
final int width = 640, height = 480; //Standard size
//#2 New attributes for data processing
// and status bar
private JLabel statusBar;
//private int addedScore;
private JMenuBar bar;
private JMenu fileMenu, editMenu, helpMenu;
private JMenuItem exitApp, clearText, displayText, addText,
aboutThisApp;
// Constructor
public TSAssn5a(String title){
//Call to JFrame constructor
super(title);
//Call initialization
init();
}
public void init(){
//Use the WindowCloser Class
addWindowListener(new WindowCloser(this));
//Set up the Window for the operating system
setLookAndFeel();
//Get the content pane
frameContainer = getContentPane();
//Create an instance ofa JTextArea
frameTextArea = new JTextArea("",
18, 70);
frameTextArea.setEditable(true);
frameTextArea.setLineWrap(true);
//Set the text area in the scroll pane
scrollForTextArea = new JScrollPane(frameTextArea);
//Create an instance of a border layout
frameLayout = new BorderLayout();
frameContainer.setLayout(frameLayout);
//#3 Add the status bar (JLabel)
frameContainer.add(scrollForTextArea, BorderLayout.CENTER);
//create a label to use as a status bar
statusBar = new JLabel(" ");
frameContainer.add(statusBar, BorderLayout.SOUTH);
setSize(height, width);
makeMenu();
//#4 Postition the window in the center of the desktop
positionWindow();
pack();
setVisible(true);
}
//----------------------------setLookAndFeel()----------------------
//Set the look and feel for the application
public void setLookAndFeel(){
try{
String lookAndFeel = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(lookAndFeel);
}
catch(Exception lFE){
//process exception
}
}
//3.1
//-----------------------setStatus()---------------------------
private void setStatus(String msg){
statusBar.setText(" " + msg);
}
//----------------------------positionWindow-----------------------------
//#4.1 Position the Frame
private void positionWindow(){
Dimension sizeOfScreen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension sizeOfFrame = this.getSize();
if(sizeOfFrame.height > sizeOfScreen.height){
sizeOfFrame.height = sizeOfScreen.height;
}
if(sizeOfFrame.width > sizeOfScreen.width){
sizeOfFrame.width = sizeOfScreen.width;
}
this.setLocation( (sizeOfScreen.width - sizeOfFrame.width) /2 ,
(sizeOfScreen.height - sizeOfFrame.height) /2 );
}
//#5----------------------------makeMenu()-----------------------------
private void makeMenu(){
//Create a menu bar
bar = new JMenuBar();
//create File menu
fileMenu = new JMenu("File");
fileMenu.setMnemonic('F');
//With menu items
//generate events and add handlers
exitApp = new JMenuItem("Exit");
exitApp.setMnemonic('X');
exitApp.addActionListener(this);
//Add the File items to File menu
fileMenu.add(exitApp);
//create Edit menu
editMenu = new JMenu("Edit");
editMenu.setMnemonic('E');
//With menu items
clearText = new JMenuItem("Clear Text");
clearText.setMnemonic('R');
displayText = new JMenuItem("Display Text");
displayText.setMnemonic('D');
addText = new JMenuItem("Add Text");
addText.setMnemonic('A');
//Add the Edit items to Edit menu
editMenu.add(clearText);
clearText.addActionListener(this);
editMenu.add(displayText);
displayText.addActionListener(this);
editMenu.add(addText);
addText.addActionListener(this);
//create Help menu
helpMenu = new JMenu("Help");
helpMenu.setMnemonic('H');
//With menu items
aboutThisApp = new JMenuItem("About...");
aboutThisApp.setMnemonic('A');
aboutThisApp.addActionListener(this);
//Add the Help items to Help menu
helpMenu.add(aboutThisApp);
//Add File, Edit, and Help to bar
bar.add(fileMenu);
bar.add(editMenu);
bar.add(helpMenu);
//Add the menu bar to the content pane
setJMenuBar(bar);
}//end makeMenu
//#3.1-----------------------main()---------------------------------
public static void main(String args[]){
new TSAssn5a("TSNU Grades");
}//end main
}//end class