can not resolve symbol in method showMessageDialog

I tried to dispaly a mesg using JOptionPane, it gives error mesg like

HWS.java:27: cannot resolve symbol

symbol : method showMessageDialog (<anonymous java.awt.event.ActionListener>,j

ava.lang.String,java.lang.String,int)

location: class javax.swing.JOptionPane

JOptionPane.showMessageDialog (this, "The","Exit", JOptionPane.INFORMATION_M

ESSAGE);

^

pls help.

Sabarish

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class HWS extends JFrame{

public HWS() {

super("Learning...");

setSize(300,300);

JLabel label2 = new JLabel("Jegan Rao");

JButton button = new JButton("Click here");

Container pane = getContentPane();

pane.setLayout(new FlowLayout());

pane.add(button);

pane.add(label2);

ActionListener al = new ActionListener(){

public void actionPerformed (ActionEvent ae){

JOptionPane.showMessageDialog (this, "The","Exit",JOptionPane.INFORMATION_MESSAGE);

}

};

button.setHorizontalAlignment(JButton.CENTER);

button.addActionListener(al);

button.setVerticalAlignment(JButton.CENTER);

label2.setHorizontalAlignment(JLabel.CENTER);

label2.setVerticalAlignment(JLabel.CENTER);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

pack();

setVisible(true);

}

public static void main(String [] args){

HWS h = new HWS();

}

}

[1505 byte] By [sabarishrla] at [2007-10-2 17:40:52]
# 1

Please post code using the code tags. There is a code button when you enter text for your message. Click on it then paste your code between the tags.

All of the JOptionPane showMessageDialog() methods require a Component as the first object argument. Your code calls showMessageDialog from inside an actionPerformed() method, which is inside an ActionListener. So 'this' is an ActionListener, not a JFrame or other Component.

Are you sure you want to call up a dialog in an actionPerformed() method? This method is called from the event thread, and blocks this thread until the dialog completes. This means no events can occur until the dialog completes, but it may require an event to complete the dialog.

atmguya at 2007-7-13 18:58:15 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
Hey mr, try making a method lik this:public void Mensaje(){JOptionPane.showMessageDialog(this, "Debes ingresar decimales");} and puting in to ActionListener
fatherjuana at 2007-7-13 18:58:15 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...