Has decent background on both Java and NetBeans
Swing is an improved UI library based on AWT (Abstract Window Toolkit), which is Java’s native UI library, and it is used to develop cross-platform desktop applications.
In accordance with the school computer’s list of software, we are using NetBeans 8.0 or 8.2 for developing GUI-based applications.
Click on New Project, and select project type to Java Class Library, which doesn’t have a main method. Then click Next.
Name your project whatever you want. Do not leave it blank. Then click Finish.
After project creation, we have to create a package to hold a single class (or perhaps it can be any object). You can skip this step and use the default package, but it is not recommended, specifically for managing multiple Java files when developing complex applications.
Select Source Packages, then hover New, and click Java Package.
Once the dialog popped up, again, feel free to name your package of your desire, BUT make sure it doesn’t have any whitespace, special characters (except period), and shouldn’t start with a number (also applies to sub-packages). You can use the period to separate words and add depth to it, e.g., clark.example. Then click Finish.
After package creation, select (click it) the package you recently created, hover New, and click JFrame Form to create a main form, where it is the vital component of a desktop application.
Name your JFrame form of your desire and ensure that it should be created on the main package (the package you’ve just created). Then click Finish.
After JFrame Form creation, it should navigate to the JFrame Form’s design editor. To demonstrate the development of some of the common and basic tasks, firstly, drag the Button from the Palette’s Swing Controls and drop it anywhere within the main form.
To add functionality to the button, select the button, then double-click it to navigate to the JFrame Form’s source code, where the action command (a private method) for this button is automatically generated, just modify its contents.
Notice the red squiggly line in this block of code, this means JOptionPane couldn’t be resolved. It indicates that we haven’t imported the class yet.
To resolve the import conflict, bring the cursor beside JOptionPane like this:
Then press Ctrl and Space at the same time on your keyboard, to automatically import the unresolved class.
Now you’re wondering, what does this block of code do? This single line of code
JOptionPane.showMessageDialog(this, “Hello World”);
does the creation of the message dialog, which contains specific text (in this instance, “Hello World”) to put in.
The private method that has its generated name is a method generated automatically by an IDE, which contains the logic or functionality when invoked (e.g., by pressing the button), so you can only modify its contents instead of hard-coding it (i.e., developing it manually).
If this dialog appears when trying to run your project:
Press OK since the main class is already selected, and it contains the main method, which is also generated automatically by an IDE after JFrame Form creation.
After the project is built, the window (at the right) will appear at the top-left of your desktop screen, which is the default location of the freshly created Swing application.
Additionally, if the button is pressed, it should show a message dialog, and it has the text of “Hello World”.
And voilà! You just created a minimal desktop application, there are numerous ways to edit and improve this application. You have the Design and Source tab editors, to do the job of beautifying and extending your desktop application.
To further expand your experience in desktop app development, try to play with the properties of every component, such as a button, a panel, or a frame (aka JFrame Form).
The Properties tab is located from the Design tab and below the Palette window. If not found; at the menu bar, click Window, hover IDE Tools, and click Properties; or simply just press Ctrl, Shift, and 7 simultaneously.
Commonly used properties are font, location, color, background (background color), and many others that are frequently used on editing the design.
Palette and Properties Tab are shown at the left.