Join Peggy Fisher for an in-depth discussion in this video Solution: GUI, part of Learning Java 8.
- This last challenge was designed to introduce you to the GUI Builder in NetBeans. Let's take a look at one possible solution. As you can see, in the left-hand side I created a project called Programming Languages. I have two files inside this project: ProgrammingLanguages.java, which is my main portion of my program, and LangaugesUI, which is my form that you see in front of you. The UI has two panels: one is called Name, the other one Languages.
In the Name panel I added a label for First Name, a text field, another label for Last Name, and another text field. In the Languages Panel I have six check-boxes. I chose to use check-boxes rather than radio buttons because a user may have more than one skill and know more than one language. Finally, at the bottom I added an Exit button. When I added all the fields and I added the exit button, when I double-clicked on it, I was able to add my code that says System.exit(0).
That allows the user to press that button and get out of the window. Okay, before we run it, let's look at the main part of the program. In the public static void main, you can see I start by creating a JFrame frame using my new frame LanguagesUI. I set the title of the frame to say "Programming Languages". I set the DefaultCloseOperation to be EXIT_ON_CLOSE. That's when they click on the red button in the top right-hand corner of the frame.
And finally, I set the frame to visible using .setVisible(true); Now let's run it so we can see what it looks like. You can see in the title bar it says Programming Languages and then you see my two panels with the information that we added. Now let's check out our exit button. Yeah, it looks like that works. This solution was done using the Graphical User Interface Builder within Netbeans; it makes it a lot easier. I hope I've sparked an interest in graphical user interfaces.
The NetBeans IDE makes it nice and easy, so have fun.
- Downloading and exploring NetBeans
- Understanding Java basics: data types, strings, arrays, and more
- Controlling flow with functions and loops
- Creating classes
- Sorting and searching arrays
- Manipulating files
- Handling errors
- Building GUIs
Skill Level Beginner
1. Getting Started
2. Java Basics
3. Flow of Control
4. Classes and Objects
5. Beyond the Basics
6. File Manipulation
7. Graphical User Interface Basics
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.