Using Message Dialogues in Applets

It is easy to implement a message dialogue, which has only one button ("OK") with in-built event handling. We show first a plain message followed by the code.

Message dialog applet (280 x 180) in action

Message dialog applet (280 x 180) in action

namespace msg_dialog_demo;

interface

uses
  java.util, java.applet.*, java.awt.*, javax.swing;

type
  MsgDialogDemo = public class(Applet, ActionListener)
  private
    btnMessage : Button;
  public
    method init; override;
    method actionPerformed(e : ActionEvent);
  end;

implementation

method MsgDialogDemo.init;
begin
  Background := Color.green.darker;
  btnMessage := new Button('Message Dialog');
  add(btnMessage);
  btnMessage.addActionListener(self);
end; 

method MsgDialogDemo.actionPerformed(e : ActionEvent);
begin
  if e.getSource = btnMessage then 
    begin
      JOptionPane.showMessageDialog(self, 'Hello World!', 'Obligatory First Greeting', JOptionPane.PLAIN_MESSAGE);
    end;
end;

end.

You can replace JOptionPane.PLAIN_MESSAGE with JOptionPane.ERROR_MESSAGE (to show an "X" icon), with JOptionPane.WARNING_MESSAGE ("!" icon) or with JOptionPane.INFORMATION_MESSAGE ("i" icon) e.g.
Information message dialog

Information message dialog

Programming - a skill for life!

How to use Dialogues in applets in Oxygene for Java