• Post Reply Bookmark Topic Watch Topic
  • New Topic

simple? dialog box  RSS feed

 
Simon Lai
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do i
Write a simple class called Message with a single public method that brings up a modal dialog with a user specified string
message. The box should have a single button with the label "OK". When the button is pressed, the box is dismissed. This class should have a single static, public method with this signature:
public static void alert(String message, Frame parent)
Thanks,
Simon
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why write your own? Java already has that implemented for you. Take a look at:
http://web2.java.sun.com/docs/books/tutorial/uiswing/components/dialog.html#create
Originally posted by Simon Lai:
how do i
Write a simple class called Message with a single public method that brings up a modal dialog with a user specified string
message. The box should have a single button with the label "OK". When the button is pressed, the box is dismissed. This class should have a single static, public method with this signature:
public static void alert(String message, Frame parent)
Thanks,
Simon

 
Daniel Searson
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a JTextField and a button to display the dialog. When the button is hit (use an ActionListener), call the alert() method and pass on the string for the button (use JTextField.getText()). The JTextField and the JButton should be in JFrame which is used as the parent frame.
The alert creates a JDialog (using a constructor with a parent frame parameter) and adds a single button (pass on the String in to its constructor). Add an ActionListener to the JButton which calls dispose() on the dialog. The best way to do this would be to make the ActionListener an inner class of the JDialog (anonymous or otherwise).
Hope that helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!