Make GUI Display (Swing) in Java
Posted January 18, 2011on:
In this post, I take one example for built GUI Display in Java, and I decide to make GUI Display in Hanoi Tower.
The Tower Hanoi or Towers of Hanoi , also called the Tower of Brahma or Towers of Brahma, is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.
The objective of the puzzle is to move the entire stack to another rod, obeying the following rules:
- Only one disk may be moved at a time.
- Each move consists of taking the upper disk from one of the rods and sliding it onto another rod, on top of the other disks that may already be present on that rod.
- No disk may be placed on top of a smaller disk.
Ok this algorithm of Hanoi Tower :
if N = 1, so
N moved from A to C directly
but if N > 1, so
move N-1 from A to B
then move N from A to C
move N-1 from B to C
N = number of disk
In making the program the Tower of Hanoi (Hanoi Towers), the author uses the program as entrepreter NetBeans 6.9.1 Java programs. The following steps for developing a program of Hanoi Tower.
1. Run NetBeans Program
2. Wait till program open
3. Make new project, with click File >> New Project, or press CTRL+SHIFT+N in keyboard. then choose Java Application in Java Categories
5. Then with click hanoi hierarchical , so will open Source Package, then click it hierarch for show up the basic/fundament Project namely hanoi , right click on this Menu then choose New >> JFrame Form
Verify the class name in the project made Hanoi. Then click Finish.
7. On menu palette on the left side of the work area, an additional component in the form of buttons, labels, text fields, etc can be made to support the Tower of Hanoi program created.
Drag some features found on Swing Controls palette menu on the left side of the java GUI work area. Here are the details of the use of features:
|GUI Form||Feature Name|
|Area Text for Showing Text||Label|
|Input Text||Text Field|
|Process Output (will show result of program)||Text Area|
|Show Loading Effect when program runs||Progress Bar|
Make program display like this :
8. Change the name of each feature is the GUI by right clicking on the relevant features, then click select Edit Text.
9. Furthermore, the variable name of each feature that has changed its name earlier, with the following details:
|Form Display in GUI
||Name of Features||Name of GUI||Name Variables
|Text of Title||jLabel1||Hanoi Tower||titleLabel|
|Text of Number Disk for Input||jLabel2||Enter Amount of Rings||ringLabel|
|Text for Process||jLabel3||Process||processLabel|
|Total Numbers of Movement’s Disks||jLabel4||Total Movements Are||totalLabel|
|Output for Process||jTextArea1||–||processTextArea|
|Display Process like Loading Effect||jProgress Bar1||–||jProgress Bar1|
|Text for input number of disks||jText Field1||–||ringTextField|
So the GUI display pictures of Tower of Hanoi program as follows: