error with WindowListener

i want a JOptionPane To appear When The User Exists The Program

on the following code:

import java.awt.*;

import javax.swing.*;

import javax.swing.JOptionPane;

import java.awt.event.ActionEvent;

import javax.swing.JPanel;

import javax.swing.JFrame;

import java.awt.event.*;

publicclass MyFrameextends JFrame

{

JLabel label=new JLabel("Hello");

MyInner inner;

MyFrame ()

{

setupGUI();

}

privatevoid setupGUI()

{

JFrame f =new JFrame();

f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

f.setTitle("Window Event");

f.setSize(550,350);

f.setResizable(false);

f.setLayout(new BorderLayout());

f.add("Center",label);

f.show(true);

inner=new MyInner();

f.addWindowListener(inner);

}

class MyInnerimplements WindowListener

{

publicvoid windowClosed(WindowEvent e)

{

JOptionPane.showMessageDialog(null,"Thanks God! " );

}

}

publicstaticvoid main(String[]args)

{

MyFrame frame=new MyFrame ();

}

}

i have an error:

MyFrame.MyInner is not abstract and does not override abstract method windowDeactivated(java.awt.event.WindowEvent) in java.awt.event.WindowListener

how do i fix it?

thank you

[2651 byte] By [First_knighta] at [2007-11-27 6:55:23]
# 1

Your inner class implements WindowListener, so it must implement all seven methods in the WindowListener interface.

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/WindowListener.html

You could simply do this for the rest of the methods:

public void windowActivated(WindowEvent e) { }

Or you could make your inner class extends WindowAdapter so you aren't forced to implement methods you don't need.

CaptainMorgan08a at 2007-7-12 18:30:55 > top of Java-index,Java Essentials,New To Java...
# 2

ok.when i added windowAdapter to the inner class

it gave me an error:'}' expected

why?and how it is fixed?

thank you

import java.awt.*;

import javax.swing.*;

import javax.swing.JOptionPane;

import java.awt.event.WindowListener;

import java.awt.event.WindowEvent;

import javax.swing.JPanel;

import javax.swing.JFrame;

import java.awt.event.*;

public class MyFrame extends JFrame

{

JLabel label=new JLabel("Hello");

MyInner inner;

MyFrame ()

{

setupGUI();

}

private void setupGUI()

{

JFrame f =new JFrame();

f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

f.setTitle("Window Event");

f.setSize(550,350);

f.setResizable(false);

f.setLayout(new BorderLayout());

f.add("Center",label);

f.show(true);

inner=new MyInner();

f.addWindowListener(inner);

}

class MyInner implements WindowListener extends WindowAdapter

{

public void windowClosed(WindowEvent e)

{

JOptionPane.showMessageDialog(null, "Thanks God! " );

}

}

public static void main(String[]args)

{

MyFrame frame=new MyFrame ();

}

}

First_knighta at 2007-7-12 18:30:55 > top of Java-index,Java Essentials,New To Java...
# 3
sorry i have fix itclass MyInnerextends WindowAdapter{}thank you
First_knighta at 2007-7-12 18:30:56 > top of Java-index,Java Essentials,New To Java...