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.
Editors IDEsJava EE

Avatar of undefined
Last Comment
jwright9

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
summerian

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
jwright9

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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy