Basic Frame v2
Basic Frame v2
Module: AOP216D/AOR216D
Introduction
In this Mrabulo Session were are going to create a basic frame (form) using the JFrame class. The
JFrame class is located in the javax.swing package. We will also use some of JFrame’s methods to
initialise the created frame. The developed solution will be stored on GitHub. The tutorial will be
concluded with a DIY (Do It Yourself) exercise.
Problem statement
Create a frame and display it. The output must resemble the following frame:
Solution
The solution is divided into three parts, namely A, B and C. In part A we create the frame, in B we test
it, and in C we store our source code on GitHub.
1
Part A: Create the frame
Step 1
Launch NetBeans.
Step 2
2
• Select Java under Categories and Java Class Library under Projects.
3
• Click Finish.
Step 3
4
• Name the class as MyFirstFrame and package it under za.ac.tut.ui
• Click Finish.
5
• Make the MyFirstFrame class a frame by extending the JFrame.
6
• Construct the frame.
Step 4
7
• Expand the folder. Under the dist folder you have a jar file that contains the
MyFirstFrame.class file.
8
Part B: Test the frame in an application
In this section we create an application executes the GUI class. To accomplish the task, we will do the
following:
Step 1
9
• Click Next. Name the project as BasicFrameApp.
• Click Finish.
10
• Inside the main method, declare a BasicFrame.
• There’s an error. This is because MyFirstFrame is not yet visible inside the application. It is
currently located in the jar file. Let’s include the jar file library to the current project. Perform
the following tasks:
1. Right click on the Libraries folder and select Add Jar/Folder.
11
2. Navigate to the location of the BasicFrame.jar file.
12
4. Now the BasicFrame library is included in the current project. Import the class, and the
error disappears.
Step 2
13
Step 3
Output:
14
Part C: Store the source code on GitHub
In this section we are going to store the source code of MyFrame.java and MyFrameApp.java on
GitHub. To accomplish this, we will perform the following:
Step 1
Step 2
On the far upper right of the page, click on Sign in if you have an account, or Sign up to create a new
one.
15
After successful login you will see something along the lines:
Step 3
16
Step 4
17
Step 5
Step 6
18
Step 7
Upload the files (MyFirstFrame.java and BasicFrameApp.java) by clicking on the link: choose your
files.
19
Step 8
Step 9
20
Step 10
Step 11
Click on Repositories.
21
Step 12
Step 13
Step 14
Copy the repository’s link by clicking on the corresponding icon . View the link (paste it here).
https://github.com/memanivbb/Basic-Frame.git
You can share this link with anyone you want to access your repository.
22
Conclusion
Please do the DIY exercise below to test your knowledge. Thank you very much for having taken time
to do the tutorial. Enjoy the rest of your day and God bless you.
DIY
Create a frame that will have your name and surname as its title. Upload your source code on your
GitHub account.
23