5
Most read
6
Most read
14
Most read
» GUI
˃
˃
˃
˃

https://www.facebook.com/Oxus20

oxus20@gmail.com

Introduction
AWT Package
Swing Package
Frame vs. JFrame

JAVA
GUI
PART I
Milad Kawesh
Agenda
» Introduction
˃ GUI (Graphical User Interface)
˃ Simple Example

» AWT and Swing Package
˃ AWT
˃ Swing
˃ JFrame vs. Frame
˃ Simple Example
2

https://www.facebook.com/Oxus20
Introduction
» A Graphical User Interface (GUI) presents a

user-friendly mechanism for interacting with
an application.
˃ Gives an application a distinctive "look" and "feel".
˃ Consistent, intuitive user-interface components give users a sense of
familiarity .
˃ Learn new applications more quickly and use them more
productively.
3

https://www.facebook.com/Oxus20
Introduction (cont..)
» Built from GUI components.
˃ Sometimes called controls or widgets

» User interacts via the mouse, the keyboard or another
form of input, such as voice recognition.
» IDEs
˃ Provide GUI design tools to specify a component's exact size and location in a visual
manner by using the mouse.
˃ Generates the GUI code for you.

˃ Greatly simplifies creating GUIs, but each IDE has different capabilities and generates
different code.
4

https://www.facebook.com/Oxus20
Simple GUI-Based Input / Output with
JOptionPane
» Most applications use windows or dialog boxes (also called

dialogs) to interact with the user.
» JOptionPane (javax.swing package) provides prebuilt dialog
boxes for input and output
˃ Displayed via static JOptionPane methods.

» Next Example uses two input dialogs to get input from the

user and a message dialog to display the sum of the given
input.

5

https://www.facebook.com/Oxus20
Simple GUI example
import javax.swing.JOptionPane;
public class Multiplier {
public static void main(String[] args) {
String firstNumber = JOptionPane.showInputDialog("Enter first number");
String secondNumber = JOptionPane.showInputDialog("Enter Second number");

int number1 = Integer.parseInt(firstNumber);
int number2 = Integer.parseInt(secondNumber);
int result = number1 * number2;
JOptionPane.showMessageDialog(null, "The Multiply of " + number1
+ " and " +number2 + " is " + result, "Result", JOptionPane.PLAIN_MESSAGE);
}
}
6

https://www.facebook.com/Oxus20
Preview

7

https://www.facebook.com/Oxus20
More on GUI
"AWT and Swing"
8

8
https://www.facebook.com/Oxus20
AWT Vs. Swing
» When Java was first released in 1995, it contained a GUI API
referred to as the Abstract Windowing Toolkit (AWT).
» The classes and interfaces of the AWT are in the java.awt
package.

» Aware of the need for a more robust API for creating GUI
applications, Sun Microsystems teamed together with

Netscape (and other industry partners) then created Swing
package.
https://www.facebook.com/Oxus20

9
AWT Vs. Swing (cont.)
» Swing is actually a part of the Java Foundation Classes

(JFC).
» The classes and interfaces of Swing are found in the
javax.swing package.
» AWT components are referred to as heavyweight
components because their implementation relies
heavily on the underlying Operating System.
10

https://www.facebook.com/Oxus20
AWT Vs. Swing (cont.)
» The look and feel of AWT components depend on the platform
the program is running on.
˃

For example, an AWT button will look like a Windows button when the program is run on a Windows
platform.

» Swing components are referred to as lightweight components
because their implementation does not rely on the underlying
Operating System.
» Because Swing components are lightweight, their appearance is
determined by you, the programmer, and not by which platform
the program is running.
11

https://www.facebook.com/Oxus20
Converting Frame to JFrame
» The names of the Swing classes all begin with a capital

"J" , like JButton, JLabel, JFrame.
» For the most part, an AWT program can be converted

to a Swing program by adding a capital J to the class
names used in the source code and recompiling the
code.
12

https://www.facebook.com/Oxus20
Creating Windows
» The basic starting point of a GUI is the container because you need a
container before you can start laying out your components.
» The java.awt.Frame and javax.swing.JFrame classes are containers that
represent a basic window with a title bar and common windowing capabilities
such as resizing, minimizing, maximizing, and closing.
» When working with JFrame objects, there are basically three steps involved to
get a JFrame window to appear on the screen:
˃ Instantiate the JFrame object in memory.
˃ Give the JFrame object a size using setSize(), setBounds(), or pack().
˃ Make the Frame appear on the screen by invoking setVisible(true).
13

https://www.facebook.com/Oxus20
JFrame and Frame Constructors
The java.awt.Frame class has four constructors:
» public Frame() or JFrame()
˃

Creates a new frame with no message in the title bar.

» public Frame(String title) or JFrame(String title)
˃

Creates a new frame with the given String appearing in the title bar.

» public Frame(GraphicsConfiguration gc) or
JFrame(GraphicsConfiguration gc)
˃

Creates a frame with the specified GraphicsConfiguration of a screen device.

» public Frame(String title, GraphicsConfiguration gc) or JFrame(String
title, GraphicsConfiguration gc)
˃

Creates a frame with the specified title and GraphicsConfiguration.

https://www.facebook.com/Oxus20

14
javax.swing.JFrame Class
» The javax.swing.JFrame class represents a window similar to
Frame, except that JFrame adds support for the Swing
component architecture.
» However, a JFrame is different in terms of how components are
added to the Frame.
» A JFrame has three panes that components can be added to:
˃ a content pane
˃ a glass pane
˃ and a root pane.

» Typically, the content pane will contain all of the components of
the JFrame.
https://www.facebook.com/Oxus20

15
Simple Example of JFrame
import javax.swing.JFrame;
public class GUIDemo {
public static void main(String[] args) {
JFrame window = new JFrame(); //create frame in memory
window.setTitle( "Oxus20" );
// Set tittle to frame
window.setSize(300, 300);
// Set Size to frame
window.setLocationRelativeTo(null); //Set location to center of monitor
//let program to close
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
// Let frame to be visible on screen
}
}

16

https://www.facebook.com/Oxus20
END

17

https://www.facebook.com/Oxus20

More Related Content

PPTX
Collections framework in java
PPTX
Java 8 streams
PPTX
Java swing
PDF
Spring Framework - Core
PPT
Exception Handling in JAVA
PPTX
Classes objects in java
PPT
Java multi threading
PPTX
Java 8 lambda
Collections framework in java
Java 8 streams
Java swing
Spring Framework - Core
Exception Handling in JAVA
Classes objects in java
Java multi threading
Java 8 lambda

What's hot (20)

PPTX
swings.pptx
PDF
PDF
Java 8 features
PPT
Java And Multithreading
PPT
Java Socket Programming
PPT
Spring ppt
PPTX
Servlets
PDF
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
PPTX
Java Server Pages(jsp)
PPT
GUI Programming In Java
PPT
Java interfaces
PDF
Asp.net state management
PPTX
Java Spring Framework
PDF
07 java collection
PPTX
Java swing
PPTX
Java 8 presentation
PDF
Inheritance In Java
PDF
Spring boot
PPTX
Inheritance in java
PPTX
Functional programming with Java 8
swings.pptx
Java 8 features
Java And Multithreading
Java Socket Programming
Spring ppt
Servlets
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Server Pages(jsp)
GUI Programming In Java
Java interfaces
Asp.net state management
Java Spring Framework
07 java collection
Java swing
Java 8 presentation
Inheritance In Java
Spring boot
Inheritance in java
Functional programming with Java 8
Ad

Viewers also liked (20)

PDF
Java GUI PART II
PDF
JAVA GUI PART III
PPTX
GUI Programming in JAVA (Using Netbeans) - A Review
PPTX
Graphical User Interface (Gui)
PPT
Java: GUI
PPT
Swing and Graphical User Interface in Java
PDF
PPT
Graphical User Interface (GUI) - 1
PPT
USER INTERFACE DESIGN PPT
PPT
Utilisation de ZK avec Java - Retour d’expérience
PPTX
Oracle ADF : Vue d'ensemble
PPT
Java swings
PPTX
Java programming-Event Handling
PPTX
java drag and drop and data transfer
PPT
Awt and swing in java
PPT
java swing programming
PPTX
Event Handling in java
PDF
Java Applet and Graphics
PDF
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
PPTX
Conditional Statement
Java GUI PART II
JAVA GUI PART III
GUI Programming in JAVA (Using Netbeans) - A Review
Graphical User Interface (Gui)
Java: GUI
Swing and Graphical User Interface in Java
Graphical User Interface (GUI) - 1
USER INTERFACE DESIGN PPT
Utilisation de ZK avec Java - Retour d’expérience
Oracle ADF : Vue d'ensemble
Java swings
Java programming-Event Handling
java drag and drop and data transfer
Awt and swing in java
java swing programming
Event Handling in java
Java Applet and Graphics
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Conditional Statement
Ad

Similar to JAVA GUI PART I (20)

PPT
Graphic User Interface (GUI) Presentation
PPTX
Awt, Swing, Layout managers
PPTX
MODULE 5.pptx gui programming and applets
PPTX
JAVA SWING PPT FOR PROGRAMMING AND CODING
PPTX
Computer Programming NC III - Java Swing.pptx
PDF
Z blue introduction to gui (39023299)
PDF
Swingpre 150616004959-lva1-app6892
PPT
Swing and AWT in java
PPT
L11cs2110sp13
PPT
Chap1 1 1
PPT
Chap1 1.1
PPT
14a-gui.ppt
PDF
GUI.pdf
DOC
java swing notes in easy manner for UG students
PPTX
Chapter 1 swings
PPT
Slot04 creating gui
PDF
28-GUI application.pptx.pdf
PPT
Java Swing Handson Session (1).ppt
PPTX
Chap 1 - Introduction GUI.pptx
Graphic User Interface (GUI) Presentation
Awt, Swing, Layout managers
MODULE 5.pptx gui programming and applets
JAVA SWING PPT FOR PROGRAMMING AND CODING
Computer Programming NC III - Java Swing.pptx
Z blue introduction to gui (39023299)
Swingpre 150616004959-lva1-app6892
Swing and AWT in java
L11cs2110sp13
Chap1 1 1
Chap1 1.1
14a-gui.ppt
GUI.pdf
java swing notes in easy manner for UG students
Chapter 1 swings
Slot04 creating gui
28-GUI application.pptx.pdf
Java Swing Handson Session (1).ppt
Chap 1 - Introduction GUI.pptx

More from OXUS 20 (16)

PDF
Java Arrays
PPTX
Java Methods
PPTX
Structure programming – Java Programming – Theory
PDF
PHP Basic and Fundamental Questions and Answers with Detail Explanation
PDF
Fundamentals of Database Systems Questions and Answers
PDF
Everything about Database JOINS and Relationships
PDF
Create Splash Screen with Java Step by Step
PDF
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
PDF
Web Design and Development Life Cycle and Technologies
PDF
Java Unicode with Cool GUI Examples
PDF
Java Regular Expression PART II
PDF
Java Regular Expression PART I
PDF
Java Guessing Game Number Tutorial
PDF
JAVA Programming Questions and Answers PART III
PDF
Object Oriented Programming with Real World Examples
PDF
Object Oriented Concept Static vs. Non Static
Java Arrays
Java Methods
Structure programming – Java Programming – Theory
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Fundamentals of Database Systems Questions and Answers
Everything about Database JOINS and Relationships
Create Splash Screen with Java Step by Step
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Web Design and Development Life Cycle and Technologies
Java Unicode with Cool GUI Examples
Java Regular Expression PART II
Java Regular Expression PART I
Java Guessing Game Number Tutorial
JAVA Programming Questions and Answers PART III
Object Oriented Programming with Real World Examples
Object Oriented Concept Static vs. Non Static

Recently uploaded (20)

PDF
FAMILY PLANNING (preventative and social medicine pdf)
PPTX
MMW-CHAPTER-1-final.pptx major Elementary Education
PPTX
Neurological complocations of systemic disease
PPTX
ACFE CERTIFICATION TRAINING ON LAW.pptx
PPTX
UCSP Section A - Human Cultural Variations,Social Differences,social ChangeCo...
PPTX
Copy of ARAL Program Primer_071725(1).pptx
PDF
English 2nd semesteNotesh biology biopsy results from the other day and I jus...
PPTX
Cite It Right: A Compact Illustration of APA 7th Edition.pptx
PPTX
GW4 BioMed Candidate Support Webinar 2025
PPTX
Theoretical for class.pptxgshdhddhdhdhgd
PDF
Chevening Scholarship Application and Interview Preparation Guide
PPTX
CHROMIUM & Glucose Tolerance Factor.pptx
PDF
IS1343_2012...........................pdf
PDF
Health aspects of bilberry: A review on its general benefits
PDF
African Communication Research: A review
PPTX
Diploma pharmaceutics notes..helps diploma students
PPT
hsl powerpoint resource goyloveh feb 07.ppt
PPTX
climate change of delhi impacts on climate and there effects
PDF
Physical pharmaceutics two in b pharmacy
PPTX
principlesofmanagementsem1slides-131211060335-phpapp01 (1).ppt
FAMILY PLANNING (preventative and social medicine pdf)
MMW-CHAPTER-1-final.pptx major Elementary Education
Neurological complocations of systemic disease
ACFE CERTIFICATION TRAINING ON LAW.pptx
UCSP Section A - Human Cultural Variations,Social Differences,social ChangeCo...
Copy of ARAL Program Primer_071725(1).pptx
English 2nd semesteNotesh biology biopsy results from the other day and I jus...
Cite It Right: A Compact Illustration of APA 7th Edition.pptx
GW4 BioMed Candidate Support Webinar 2025
Theoretical for class.pptxgshdhddhdhdhgd
Chevening Scholarship Application and Interview Preparation Guide
CHROMIUM & Glucose Tolerance Factor.pptx
IS1343_2012...........................pdf
Health aspects of bilberry: A review on its general benefits
African Communication Research: A review
Diploma pharmaceutics notes..helps diploma students
hsl powerpoint resource goyloveh feb 07.ppt
climate change of delhi impacts on climate and there effects
Physical pharmaceutics two in b pharmacy
principlesofmanagementsem1slides-131211060335-phpapp01 (1).ppt

JAVA GUI PART I

  • 2. Agenda » Introduction ˃ GUI (Graphical User Interface) ˃ Simple Example » AWT and Swing Package ˃ AWT ˃ Swing ˃ JFrame vs. Frame ˃ Simple Example 2 https://www.facebook.com/Oxus20
  • 3. Introduction » A Graphical User Interface (GUI) presents a user-friendly mechanism for interacting with an application. ˃ Gives an application a distinctive "look" and "feel". ˃ Consistent, intuitive user-interface components give users a sense of familiarity . ˃ Learn new applications more quickly and use them more productively. 3 https://www.facebook.com/Oxus20
  • 4. Introduction (cont..) » Built from GUI components. ˃ Sometimes called controls or widgets » User interacts via the mouse, the keyboard or another form of input, such as voice recognition. » IDEs ˃ Provide GUI design tools to specify a component's exact size and location in a visual manner by using the mouse. ˃ Generates the GUI code for you. ˃ Greatly simplifies creating GUIs, but each IDE has different capabilities and generates different code. 4 https://www.facebook.com/Oxus20
  • 5. Simple GUI-Based Input / Output with JOptionPane » Most applications use windows or dialog boxes (also called dialogs) to interact with the user. » JOptionPane (javax.swing package) provides prebuilt dialog boxes for input and output ˃ Displayed via static JOptionPane methods. » Next Example uses two input dialogs to get input from the user and a message dialog to display the sum of the given input. 5 https://www.facebook.com/Oxus20
  • 6. Simple GUI example import javax.swing.JOptionPane; public class Multiplier { public static void main(String[] args) { String firstNumber = JOptionPane.showInputDialog("Enter first number"); String secondNumber = JOptionPane.showInputDialog("Enter Second number"); int number1 = Integer.parseInt(firstNumber); int number2 = Integer.parseInt(secondNumber); int result = number1 * number2; JOptionPane.showMessageDialog(null, "The Multiply of " + number1 + " and " +number2 + " is " + result, "Result", JOptionPane.PLAIN_MESSAGE); } } 6 https://www.facebook.com/Oxus20
  • 8. More on GUI "AWT and Swing" 8 8 https://www.facebook.com/Oxus20
  • 9. AWT Vs. Swing » When Java was first released in 1995, it contained a GUI API referred to as the Abstract Windowing Toolkit (AWT). » The classes and interfaces of the AWT are in the java.awt package. » Aware of the need for a more robust API for creating GUI applications, Sun Microsystems teamed together with Netscape (and other industry partners) then created Swing package. https://www.facebook.com/Oxus20 9
  • 10. AWT Vs. Swing (cont.) » Swing is actually a part of the Java Foundation Classes (JFC). » The classes and interfaces of Swing are found in the javax.swing package. » AWT components are referred to as heavyweight components because their implementation relies heavily on the underlying Operating System. 10 https://www.facebook.com/Oxus20
  • 11. AWT Vs. Swing (cont.) » The look and feel of AWT components depend on the platform the program is running on. ˃ For example, an AWT button will look like a Windows button when the program is run on a Windows platform. » Swing components are referred to as lightweight components because their implementation does not rely on the underlying Operating System. » Because Swing components are lightweight, their appearance is determined by you, the programmer, and not by which platform the program is running. 11 https://www.facebook.com/Oxus20
  • 12. Converting Frame to JFrame » The names of the Swing classes all begin with a capital "J" , like JButton, JLabel, JFrame. » For the most part, an AWT program can be converted to a Swing program by adding a capital J to the class names used in the source code and recompiling the code. 12 https://www.facebook.com/Oxus20
  • 13. Creating Windows » The basic starting point of a GUI is the container because you need a container before you can start laying out your components. » The java.awt.Frame and javax.swing.JFrame classes are containers that represent a basic window with a title bar and common windowing capabilities such as resizing, minimizing, maximizing, and closing. » When working with JFrame objects, there are basically three steps involved to get a JFrame window to appear on the screen: ˃ Instantiate the JFrame object in memory. ˃ Give the JFrame object a size using setSize(), setBounds(), or pack(). ˃ Make the Frame appear on the screen by invoking setVisible(true). 13 https://www.facebook.com/Oxus20
  • 14. JFrame and Frame Constructors The java.awt.Frame class has four constructors: » public Frame() or JFrame() ˃ Creates a new frame with no message in the title bar. » public Frame(String title) or JFrame(String title) ˃ Creates a new frame with the given String appearing in the title bar. » public Frame(GraphicsConfiguration gc) or JFrame(GraphicsConfiguration gc) ˃ Creates a frame with the specified GraphicsConfiguration of a screen device. » public Frame(String title, GraphicsConfiguration gc) or JFrame(String title, GraphicsConfiguration gc) ˃ Creates a frame with the specified title and GraphicsConfiguration. https://www.facebook.com/Oxus20 14
  • 15. javax.swing.JFrame Class » The javax.swing.JFrame class represents a window similar to Frame, except that JFrame adds support for the Swing component architecture. » However, a JFrame is different in terms of how components are added to the Frame. » A JFrame has three panes that components can be added to: ˃ a content pane ˃ a glass pane ˃ and a root pane. » Typically, the content pane will contain all of the components of the JFrame. https://www.facebook.com/Oxus20 15
  • 16. Simple Example of JFrame import javax.swing.JFrame; public class GUIDemo { public static void main(String[] args) { JFrame window = new JFrame(); //create frame in memory window.setTitle( "Oxus20" ); // Set tittle to frame window.setSize(300, 300); // Set Size to frame window.setLocationRelativeTo(null); //Set location to center of monitor //let program to close window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setVisible(true); // Let frame to be visible on screen } } 16 https://www.facebook.com/Oxus20