Using Widgets in Applets

This section shows you how to write applets that are like forms-based Pascal programs with widgets such as buttons and combo boxes. The demonstration applets will convert readily to applications as we have shown for Dharmesh Tailor's mouse applet and our path applet, but you can also use much of the code in a frame-based application starting from scratch as shown in Frame-Based Applications.

Some of the widgets that we use in demonstrations do not appear in the title of a section. Here is an alphabetic list with a link to a section in which we use each one.

Button, JColorChooser, JComboBox, JFileChooser, JLabel, JOptionPane (for message, option and input dialogues), JPanel, JRadioButton, JTextArea, Label, TextArea (the equivalent of Delphi's TMemo), TextField (the equivalent of Delphi's TEditText)

Widgets beginning with J are in the javax.swing package and contain more functionality than their counterparts in its predecessor, the java.awt package. Others you are likely to need are JButton (for buttons with images), JList (the equivalent of Delphi's TListBox) and JMenu. Those of you who like a challenge might like to try using a JTree. For other available widgets you can consult the list of direct known subclasses of JComponent.

We demonstrate the use of these components in our shorter section on frame-based applications: JButton, JDesktopPane, JInternalPane, JLabel JList, JMenu, JMenuBar, JMenuItem, JPanel, JRadioButton, JTable, JTextArea, Label, TextField. Their use in applets is very similar.

Follow the links below to the demonstrations. We provide the code and screenshots of the applets but do not include the applets in web pages because the actions are obvious. (If you want to develop one you can compile the source code to a jar file and write a simple HTML file to run it. For many simple examples of .oxygene project files and HTML files see the first applets in this tutorial such the one demonstrating the drawing of lines.)

Programming - a skill for life!

Mouse and keyboard input, graphics (including Graphics2D), threads and widgets in Oxygene for Java applets