Link to home
Start Free TrialLog in
Avatar of jwright9
jwright9

asked on

Java Swing Message Box in a Struts action

I found the listed program on Roseindia.net.  Great site I recommend it.  Here is the code:

import javax.swing.*;
import java.awt.event.*;

public class ShowDialogBox{
  JFrame frame;
  public static void main(String[] args){
    ShowDialogBox db = new ShowDialogBox();
  }

  public ShowDialogBox(){
    frame = new JFrame("Show Message Dialog");
    JButton button = new JButton("Click Me");
    button.addActionListener(new MyAction());
    frame.add(button);
    frame.setSize(400, 400);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

  public class MyAction implements ActionListener{
    public void actionPerformed(ActionEvent e){
      JOptionPane.showMessageDialog(frame,"Roseindia.net");
    }
  }
}

I want to display the JOptionPane running it from a Struts Action class.  Is this possible sinceI'm afraid I must run in a JFrame or something like that?  I want to display informational messages and warnings using is.  Any ideas?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of summerian
summerian
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jwright9
jwright9

ASKER

Very good complete answer.  Swing components won't work for me.  I saw Java Server Faces mentioned for this purpose but I know very little about them.  Thanks.