Frame-based Applications

This section will be short, because much of the demonstration code for applets can be used in applications. The demonstration applets will convert readily to applications as we have shown for Dharmesh Tailor's mouse applet and our path applet and will then run on the Raspberry Pi. In this tutorial we show you how to begin a frame-based application, without any references to an applet. The structure is based on Brian Long's Desktop "SwingSample" included with Oxygene for Java.

Below we show the source code and the project file of the minimal application that produced the customary greeting:

Application in action

Application in action

On the next page we provide details of the conversion of one of our applets to an application with a structure like this one but with more widgets. On the following pages you can see examples of the use of these components: JButton, JDesktopPane, JInternalPane, JLabel (with downloaded image) JList, JMenu, JMenuBar, JMenuItem, JPanel, JRadioButton, JTable, JTextArea, Label, TextField.

These applications will run on the Raspberry Pi with Version 6 of the Open JDK, sometimes after slight changes to the code as noted. The functionality remains even when the appearance is different. After compiling on a PC you can copy the jar file to a memory stick, open the containing folder with the File Manager on the Pi, then double click on the filename to execute the application.

You may find useful these links to the use of components in applets: 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)

The code of greeting_app.pas

See the equivalent RemObjects C# Code below.

namespace greeting_app;

interface

uses
  java.util, java.awt.*, javax.swing;
   
type
  GreetingDemo = public class(JFrame)
  private
    lblGreeting : Label;
    verticalBox : Box;
   
  public
    constructor;
    class method Main(args: array of String);   
  end;

implementation

constructor GreetingDemo;
begin
  lblGreeting := new Label('Hello World!');
  verticalBox := Box.createVerticalBox;
  verticalBox.add(lblGreeting);
  add(verticalBox);

  //Ensure app closes when you click the close button
  DefaultCloseOperation := JFrame.EXIT_ON_CLOSE;
  //Set window caption and size
  Title := 'Greeting Demo';
  Size := new Dimension(250, 70);		
  setVisible(true); 
end;

class method GreetingDemo.Main(args: array of String);
begin
  new GreetingDemo;
end;

end.

The code of greeting_app.oxygene

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup>
    <OutputType>Executable</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="rt.jar" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="greeting_app.pas" />
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)\RemObjects Software\Oxygene\RemObjects.Oxygene.Cooper.targets" />
</Project>

RemObjects C# Code of Greeting

using java.util;
using java.awt;
using javax.swing;

namespace greeting_app_cs
{
  public class GreetingDemo : JFrame
  {
    private Label lblGreeting;    
    private Box verticalBox;
    
    public GreetingDemo()
    {  
      lblGreeting = new Label("Hello World!");
      verticalBox = Box.createVerticalBox();
      verticalBox.add(lblGreeting);
      add(verticalBox);
      //Ensure app closes when you click the close button
      DefaultCloseOperation = JFrame.EXIT_ON_CLOSE;
      //Set window caption and size
      Title = "Greeting Demo";
      Size = new Dimension(250, 70);    
      setVisible(true);     
    }
  
    public static void Main(string[] args)
    {
      new GreetingDemo();
    }
  }  
}


Programming - a skill for life!

Console, frame-based and Android applications, applets, game development, networking and language features