Computer
Programming 3 LABELING THE TEXT
OCC101
In this lesson you will learn the basic swing components such as JLabel, JTextField,
JButton and Jpanel. This is you put text or caption in such components to make your program
more informative, attractive and meaningful.
At the end of this lesson, the student should be able to:
Understand the syntax for JLabel
Learn the format of JTextFields
Combine JLabel and JTextFields in the program
Understand the JPanel command
Learn the Syntax of JPanel
Design your own program using JLabel and JTextFields.
=======================================================================
One Cainta College (BSIS Department) Page | 1
JButton
JButton is in implementation of a push button. It is used to trigger an action if the user
clicks on it.
JButton can display a text, an icon, or both.
JLabel
JLabel is a simple component for displaying text, images or both. It does not react to
input events.
JLabel Button is the component window used for labeling the text to make it more
readable and understandable to the users who will be using the program.
JTextField
JTextField is a text component that allows editing of a single line of non-formatted text.
Java JPanel
The JPanel is a simplest container class. It provides space in which an application can
attach any other component. It inherits the JComponents class. It doesn't have title bar.
Jpanel Class Declaration
public class JPanel extends JComponent implements Accessible
=======================================================================
One Cainta College (BSIS Department) Page | 2
Commonly used Constructors:
Constructor Description
JPanel() It is used to create a new JPanel with a double buffer and a
flow layout.
JPanel(boolean It is used to create a new JPanel with FlowLayout and the
isDoubleBuffered) specified buffering strategy.
JPanel(LayoutManager It is used to create a new JPanel with the specified layout
layout) manager.
Example:
b.addActionListener(this);
=======================================================================
One Cainta College (BSIS Department) Page | 3
Write the output here:
=======================================================================
One Cainta College (BSIS Department) Page | 4
Instructions: Open the links below to read more concepts of Graphical User Interface in
Java.
1. https://stackoverflow.com/questions/17058159/how-do-i-get-a-jlabel-to-show-
over-a-jbutton
2. https://www.javatpoint.com/java-jtextfield
3. http://zetcode.com/javaswing/basicswingcomponents/
Instructions: Do the following program as your activity 1 and write the output of the
program on the box provided. Next Meeting will be your submission.
=======================================================================
One Cainta College (BSIS Department) Page | 5
=======================================================================
One Cainta College (BSIS Department) Page | 6
Output 1
=======================================================================
One Cainta College (BSIS Department) Page | 7
Instructions:
Create a program that will display the login password window.
Write your Codes here:
=======================================================================
One Cainta College (BSIS Department) Page | 8