Using a Colour Chooser in Applets

We used code on this Java page to produce this simple example of a JColorChooser. The first screenshot shows the dialogue and the second shows the tiny applet after choosing the colour. The straightforward code follows the screenshots.

Colour Chooser

Colour Chooser

Colour Chosen

Colour Chosen

namespace color_dialog_demo;

interface

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

implementation

method ColorDialogDemo.init;
begin
  Background := Color.green.darker;
  btnOption := new Button('Colour Chooser');
  add(btnOption);
  btnOption.addActionListener(self);
end;

method ColorDialogDemo.actionPerformed(e : ActionEvent);
var
  chosenColour : Color; 
begin
  chosenColour := JColorChooser.showDialog(self, 'Choose Background Colour',  Color.white);
  Background := chosenColour;
end;

end.

Programming - a skill for life!

How to use Dialogues in applets in Oxygene for Java