In your Comp504 folder (make one if you don't already have one),
make a folder called "Labs". We will put all of our lab code
into sub-folders in this Labs folder.
It is highly suggested that you also create another, "Assignments"
folder in your Comp504 folder to put your homework code.
Create an Eclipse workspace -- a workspace is
a collection of projects, which is the collection of files needed
to make a a specific application (e.g. homework or lab assignment)
Start Eclipse -- the "Workspace Launcher" dialog should show up.
If you have gotten past this point already for some reason, you can get
back to it by slecting "File/Switch
Workspace/Other..." from the main Eclipse menu.
Click the "Browse" button and browse to and highlight the
Labs folder
you made.
Click the "Ok" button twice and Eclipse will restart in your new
workspace.
If this is the first time you are using the workspace, you will
need to click the "Workbench: Go to the workbench" icon in the
middle right of the Eclipse screen.
Adjust the WindowBuilder settings -- this only needs to
be done once ever.
Create a new Java Project -- Sets up a specific Java application to be developed.
Be sure that the upper right corner of the Eclipse window has a
little button labeled "Java", indicating that Eclipse is using its
default "Java perspective". If not, click the "Open
Perspective" icon in the upper right corner and select the Java
perspective.
Click "File/New/Java Project" from the main Eclipse menu.
Project Name = "Lab00"
Be sure that the following default values are indeed set:
"Use default location" selected
Use execution environment JRE
= JavaSE-1.8 (or whatever the latest version is)
"Create separate folder sfor sources and class files"
selected
"Add project to working sets" NOT selected.
Click "Finish". A new folder in Labs called
"Lab01" with subfolders, "src" and "bin" should be created.
The .java source files will go in "src" and the .class files will go in
"bin".
Create a WindowBuilder application - adds a
JFrame-based application to the project based on a pre-defined template for
a WindowBuilder graphical user interface type (GUI) Java application
Add a new package under the "src" folder:
In the "Package Explorer" tab, right-click the "src" folder and
select "New/Package"
Set the "Name" of the new package to "view" and click "Finish".
Be sure that the new "view" package is highlighted and follow the instructions in the
Using
WindowBuilder resource page to
"Create a Simple GUI Application"
Run your working, albeit not too exciting application!
Highlight the JFrame file in the package explorer that you created
(probably "MainAppFrame.java") and click the green "Run" button on the
main Eclipse toolbar.
If you haven't already saved all your files a "Save and Launch"
dialog will pop up asking you to save any unsaved files.
Click "Select All" and check the box that says "Always save resources
before launching" and never be bothered by this again.
A small blank window will appear. Hooray!
Add some GUI components to make your application more
interesting
Open the WindowBuilder "What-You-See-Is-What-You-Get" (WSIWYG) GUI
editor:
Double-click the JFrame file
(probably "MainAppFrame.java") to
open it in the editor if it is not already open.
Click on the "Design" tab at
the bottom of the editor pane. This will open
WindowBuilder's
Add a panel to the frame:
In the WindowBuilder component palette, click on the "JPanel"
component.
Holding the mouse (without clicking!) over various
locations in the frame will highlight each of the 5 possible
locations that the panel can be placed onto the frame.
Click on the top location (the "North" location) to drop the
panel into the frame.
Change the name of the variable referencing the new panel by
selecting the panel in the frame and going to the WindowBuilder
Properties tab. Under
the entry called "Variable", change
the value to "pnlControl" (we
are making a "control panel").
Note the naming convention being used here. By
prefixing the name with "pnl",
one can tell at a glance exactly what sort of component the
variable references. We will use prefixes like "pnl",
"lbl", "btn",
etc. to indicate panels, labels, button and other components.
This is incredibly useful. Good naming practices
are paramount!
Be sure that the panel is selected and change the background
color of panel by clicking on the ellipses button ("...")
next to the "background" entry in the WindowBuilder
Properties tab.
Run your application to see your colored panel on the frame.
Add a label to the panel:
In the WindowBuilder component palette, click on the "JLabel"
component.
Select a JLabel from the
WindowBuilder component palette and drop it onto the
panel you added earlier.
Change the name of the label to something more useful, e.g. "lblInfo".
Enter the text for the label in the "text"
entry in the label's Properties.
Run your application to test it.
Add a button to the panel:
Select a JButton from the
component palette and add it to the panel.
Change the name of the button to something more useful, e.g. "btnRun".
Set the button's text property
to whatever you like (recommendation: something related to the name
of the button).
Run your application. You should be able to
click the button but it won't do anything...yet.
Add behavior to the button:
In the WindowBuilder designer, double-click the button.