Using Option Dialogues with Customised Buttons in Applets

We used the code for the customised buttons on this Java page to get us started. You can change the applet size (initially 300 x 300) by pressing buttons. A screenshot and the code follow.

Customised buttons for option dialogue applet (300 x 300)

Customised buttons for option dialogue applet (initially 300 x 300)

namespace cust_option_dialog_demo;

interface

uses
  java.util, java.applet.*, java.awt.*, javax.swing;
type
  CustOptionDialogDemo = public class(Applet, ActionListener)
  private
    btnOption : Button;
  public
    method init; override;
    method actionPerformed(e : ActionEvent);   
  end;

implementation

method CustOptionDialogDemo.init;
begin
  Background := Color.green.darker;
  btnOption := new Button('Option Dialog');
  add(btnOption);
  btnOption.addActionListener(self);
end;

method CustOptionDialogDemo.actionPerformed(e : ActionEvent);
var
  buttonCode, messageType : Integer;
  sizeOptions : array[0 .. 2] of String := ['Small', 'Medium', 'Large']; 
begin
  messageType := JOptionPane.QUESTION_MESSAGE;
  if e.getSource = btnOption then
    begin 
      buttonCode := JOptionPane.showOptionDialog(self, 'Choose an option', 'Choose an applet size',
                                                 0, messageType, nil, sizeOptions, 'Small');
      case buttonCode of
        0 : setSize(100, 100);
        1 : setSize(200, 200);
        2 : setSize(300, 300);
      end;
    end;
end;

end.


Programming - a skill for life!

How to use Dialogues in applets in Oxygene for Java