UI Starter provides the framework to quickly setup and start a graphical application.
The framework actually handles for you:
- application initialization (i.e. main frame creation and size/location setup);
- application default commands for Exit and About actions for other all OS but MacOS;
- MacOS specific: the framework prepares desktop integration regarding name, Dock icon, default commands for Preferences, About and Exit actions;
- application persistent storage of frame location and size, i.e. future launch of the same application restores these properties.
Usage sample
Here is a simple code snippet taken from our tutorial package:
import com.plealog.genericapp.api.EZGenericApplication;
public class TutorialOneUIStarter {
public static void main(String[] args) {
EZGenericApplication.initialize("TutorialOneUIStarter");
EZGenericApplication.startApplication(args);
}
}
Of course, this tutorial example does nothing else than starting an empty frame. So, simply add the necessary code to handles your branding and install a component within the main frame:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
public class TutorialTwoUIStarter {
public static void main(String[] args) {
EZGenericApplication.initialize("TutorialTwoUIStarter");
// Add application branding
EZApplicationBranding.setAppName("TutorialTwoUIStarter");
EZApplicationBranding.setAppVersion("1.0");
EZApplicationBranding.setCopyRight("Created by me");
EZApplicationBranding.setProviderName("Plealog Software");
// Add a listener to application startup cycle (see below)
EZEnvironment.setUIStarterListener(new MyStarterListener());
// Start the application
EZGenericApplication.startApplication(args);
}
private static class MyStarterListener implements EZUIStarterListener {
@Override
public Component getApplicationComponent() {
// This method is called by the framework to obtain the UI main
// component to be displayed in the main frame.
JPanel mainPanel = new JPanel(new BorderLayout());
JTabbedPane tabPanel = new JTabbedPane();
tabPanel.add("My First Component", new JPanel());
mainPanel.add(tabPanel, BorderLayout.CENTER);
return mainPanel;
}
@Override
public boolean isAboutToQuit() {
// You can add some code to figure out if application can exit.
// Return false to prevent application from exiting (e.g. a background
// task is still running).
// Return true otherwise.
// Do not add a Quit dialogue box to ask user confirmation: the framework
// already does that for you.
return true;
}
@Override
public void postStart() {
// This method is called by the framework just before displaying UI
// (main frame).
}
@Override
public void preStart() {
// This method is called by the framework at the very beginning of
// application startup.
}
}
}
Now, you have a fully working UI starter sample to start with. More code snippets are available in our tutorial.