[font=Arial][b][color=#33CCFF]This is my code...
CODE
import java.awt.*;
import java.awt.event.*;
public class MadLib extends Frame implements WindowListener {
private TextArea display;
private MadDialog dialog;
public MadLib() {
super("MadLib Game");
display = new TextArea(" ", 7, 60,
TextArea.SCROLLBARS_VERTICAL_ONLY);
display.setFont(new Font("Arial", Font.PLAIN, 16));
display.setEditable(false);
add(display);
addWindowListener(this);
setLocation(100, 150);
pack();
dialog = new MadDialog(this);
dialog.addWindowListener(this);
dialog.setLocation(150, 100);
dialog.setVisible(true);
setVisible(true);
}
public static void main(String[] args) {
MadLib ml = new MadLib();
}
private void buildStory() {
String story = " ";
String[] segs = {"One fine ", " night, a ", " named ",
" ", " had a dream. It was the ", " ", " dream since ",
" dreamt that a ", " ", " ", " and ", " on a ", " ",
". In this dream, and old ", " said to him, \"", "\" ", " ",
" interpreted this as a sign. To ", ", it meant, ", " ", " ",
" your ", " ", " a ", " when the moon is ", "." };
String[] s = dialog.getStringarray();
for (int i = 0; i < s.length; i++) {
story += segs[i] + s[i];
}
story += segs[segs.length - 1];
display.setText(story);
}
public void windowClosing(WindowEvent e) {
if (e.getSource() == this) {
dispose();
System.exit(0);
}
else if (e.getSource() instanceof Dialog) {
buildStory();
((Dialog)e.getSource()).setVisible(false);
}
}
//the rest of them must be delcared
public void windowActivated(WindowEvent e) { }
public void windowCLosed(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public void windowOpened(WindowEvent e) { }
}
I am using BlueJ and when I compile the code, I get this error message: "MadLib is not abstract and does not override abstract method windowClosed(java.awt.event.WindowEvent) in java.awt.event.WindowListener
Please help me with this. I am not sure how to fix this problem! Thank you!
This post has been edited by Help Me Learn Java: 18 Mar, 2007 - 09:10 AM