Graphical User Interface (GUI)
A graphical user interface makes using an application much easier
and more visually appealing. As opposed to a text based console
program, a gui requires a little more coding. We need to figure
out that interface.
I wrote a library that will allow you to get up and running with guis. Here are the instructions and download for that library.
Also this year we will use a GUI builder. In the real world, no one places components by hand, but uses a graphical builder. We are using one here. To install it, put this file in your bluej - lib - extension folder and reset bluej.
In Java, the main library of gui components (like menus, textfields,
buttons, etc [See here
for a list of them.]) is called Swing.
For textfields this is the api
Create a new project called GUI and create classes for each of the following assignments.
- Create a gui called Counting that will have a textfield and a button. The textfield will start at 0. Everytime they hit the button the number will go up by one.
- Create a gui called Average with 2 textboxes and a button One textbox will be their grade and one will be their average (which you calculate). Each time they hit the button, it will update their average with that grade. so if they put in 50, and hit the button, average would be 50. If they then put in 100, hit button, average would be 75. If they then put in 60, and hit button, it would average to 70.
- Create a gui called ConvertUnits where there will be 2 textfields and a button that will convert between inches and centimeters. If they put in inches, it will convert to centimeters. If they put in cm it will convert to inches.
- Create a gui called NextNum that will have a textarea and a button and each time the button is pressed another line is added to the textarea (myTextArea.append("sdfsdf\n"); //where \n is for new line). The line will say "This is line 1" then "This is line 2")
- Have a GUI application with a textfield and 2 buttons - which will say hide or show which will hide the word or
show the word. (you might want to use setVisible(true or false) for the textfield
- Create a gui called PSAccount with 3 textboxes and a button.
The first two text boxes will be for first name and then last
name. When they hit the submit button, the three textbox will
then create a Portland Schools account (which is the first 5 of
last name and then the first letter of first name).
- Create a gui called DrawCircle that will have a textfield and
a button. The textfield will take in how large a circle you will
draw and the button will be called draw and it will draw that
circle. Advanced, instead of a textfield for size, use a slider. Also use a dropdown for color.
- to access graphics to draw you can say: Graphics g=getGraphics();
- now you can say g.drawLine(.... or anything to g