0% found this document useful (0 votes)
4 views

Lecture-2-Basics-of-Java

The document provides an overview of Java GUI applications, highlighting their event-driven nature and the use of AWT and Swing packages. It details common Swing controls such as JFrame, JLabel, JTextField, and JButton, along with methods for setting and getting text. Additionally, it explains how to create dialog boxes using JOptionPane and the parseInt() method for converting strings to integers.

Uploaded by

hanslebite
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lecture-2-Basics-of-Java

The document provides an overview of Java GUI applications, highlighting their event-driven nature and the use of AWT and Swing packages. It details common Swing controls such as JFrame, JLabel, JTextField, and JButton, along with methods for setting and getting text. Additionally, it explains how to create dialog boxes using JOptionPane and the parseInt() method for converting strings to integers.

Uploaded by

hanslebite
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

CPE 206L DATA STRUCTURE AND ALGORITHM

SLIDESMANIA.COM

ENGR. WENDY O. SANTOS


GUI Application
Graphical User Interface
These are applications with menus, toolbars, buttons, scroll
bars, and other controls which depend on the computer mouse
for input.
Java GUI applications are event-driven, meaning nothing happens until an
application is called upon to respond to some event.
Java GUI application will come from two packages: the Abstract
Windowing Toolkit (AWT) and Swing.
SLIDESMANIA.COM
Swing Controls
The controls we use in GUI applications will be
Swing components.
These components are defined in the javax.swing
package and all have names beginning with J.
SLIDESMANIA.COM
Common Swing Controls

JFrame control:

The frame control is the basic ‘container’ for other controls.


It is the framework for a Java project.
The title property establishes the caption information.
SLIDESMANIA.COM
Common Swing Controls
JLabel control:

The label control allows placement of formatted text


information on a frame (text property).
SLIDESMANIA.COM
Common Swing Controls
JTextField control:

The label control allows placement of formatted text


information on a frame (text property).
SLIDESMANIA.COM
Common Swing Controls
JButton control:

The button control is used to start some action.


The text property is used to establish the caption.
SLIDESMANIA.COM
setText() and getText() Methods
setText() - is a method used to set the text content of a component.

getText() - is a method used to retrieve the current


text content of a component.
SLIDESMANIA.COM
Dialog Box / Message Box
You can use the JOptionPane class to create message boxes or dialog boxes.

‘showMessageDialog()’ is used for displaying a message box with a


message.
SLIDESMANIA.COM
Dialog Box / Message Box
Syntax:
JOptionPane.showMessageDialog (component, message, title, messageType)

Component - typically a JFrame or null. If null, the dialog is centered on the screen.
Message - the message to be displayed in the dialog.
title - the title of the dialog. It is displayed in the title bar of the
dialog window.
messageType - is an integer constant representing the type of the
message. It determines the icon and visual style of the dialog.
SLIDESMANIA.COM
Dialog Box / Message Box
Common message types:

JOptionPane.PLAIN_MESSAGE: Default message type.


JOptionPane.ERROR_MESSAGE: Error message with an error icon.
JOptionPane.INFORMATION_MESSAGE: Information message
with an information icon.
JOptionPane.WARNING_MESSAGE: Warning message with a
warning icon.
JOptionPane.QUESTION_MESSAGE: Question
SLIDESMANIA.COM

message with a question icon.


parseInt() method
Use parseInt() to convert String to an int for further
processing or calculations.
SLIDESMANIA.COM

You might also like