SlideShare a Scribd company logo
GETTING STARTED WITH GUI PROGRAMMING

By .Muhammad Shebl
OBJECTIVES
1.   To create user interfaces using frames.
2.   GUI components
3.   Adding Component
4.   To understand the role of layout managers
5.   Panels
6.   Actions
7.   Set & Get
FRAMES
 Frame is a window that is not contained
 inside another window.
 Frame is the basis to contain other user
 interface components in Java GUI
 applications.
 For Swing GUI programs, use JFrame class to
 create widows.
CREATING FRAMES
 import javax.swing.*;
 public class Main extends JFrame {
    public Main() {
         setSize(200, 150);
         setTitle("MUFIX");
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setLocationRelativeTo(null);
         setVisible(true);
    }

     public static void main(String[] args) {
        Main m=new Main();
     }
 }
CENTERING FRAMES
By default, a frame is displayed in the upper-left
 corner of the screen.
To display a frame at a specified location, you can
  use the setLocation(x,y) method in the JFrame
  class.     (0, 0)


                      Screen

                               (x, y)


                                             Frame
                                                       getHeight()   screenHeight




                                          getWidth()




                                        screenWidth
CREATING GUI OBJECTS
                                                 Label   Text    Check   Radio
                                                         field   Box     Button

                       Button

// Create a button with text OK
JButton jbtOK = new JButton("OK");



// Create a label with text "Enter your name: "
JLabel jlblName = new JLabel("Enter your name: ");

// Create a text field with text "Type Name Here"                  Combo
JTextField jtfName = new JTextField("Type Name Here");             Box

// Create a check box with text bold
JCheckBox jchkBold = new JCheckBox("Bold");

// Create a radio button with text red
JRadioButton jrbRed = new JRadioButton("Red");

// Create a combo box with choices red, green, and blue
JComboBox jcboColor = new JComboBox(new String[]{"Red", "Green", "Blue"});
LAYOUT MANAGERS
 The GUI components are placed in containers. Each
 container has a layout manager to arrange the GUI
 components within the container.
 Layout managers are set in containers using the
 setLayout(LayoutManager)     method in a container.
 ◦ FlowLayout

 ◦ GridLayout

 ◦ BorderLayout
FlowLayout MANAGER
The components are arranged in the container from
left to right in the order in which they were added.
When one row becomes filled, a new row is started.
container.setLayout(newFlowLayout(FlowLayout.LEFT,5,5));
FlowLayout             CONSTRUCTORS
 public FlowLayout(int align, int hGap, int vGap)
 Constructs a new FlowLayout with a specified alignment,
 horizontal gap, and vertical gap. The gaps are the distances in
 pixel between components.
 public FlowLayout(int alignment)
 Constructs a new FlowLayout with a specified alignment
 and a default gap of five pixels for both horizontal and
 vertical.
 public FlowLayout()
 Constructs a new FlowLayout with a default center alignment and
 a default gap of five pixels for both horizontal and vertical.
GridLayout MANAGER
 The GridLayout manager arranges components in a grid
 (matrix) formation with the number of rows and columns
 container.setLayout(newGridLayout(3,2,5,5));
GridLayout CONSTRUCTORS
 public GridLayout(int rows,int columns)

 Constructs a new GridLayout with the specified
 number of rows and columns.
 public GridLayout(int rows, int columns,
 int hGap, int vGap)
 Constructs a new GridLayout with the specified
 number of rows and columns, along with specified
 horizontal and vertical gaps between components.
BorderLayout MANAGER
  The BorderLayout manager divides the container
  into five areas: East, South, West, North, and Center.
container.setLayout(new BorderLayout(5,10));
container.add(jbtOK,BorderLayout.NORTH);
USING PANELS AS SUB-CONTAINERS
 Panels act as sub-containers for grouping user interface
  components.

 It is recommended that you place the user interface
  components in panels and place the panels in a frame. You
  can also place panels in a panel.

 To add a component to JFrame, you actually add it to the
  content pane of JFrame. But to add a component to a panel,
  you add it directly to the panel using the add method.
CREATING A JPanel
 You can use
   new JPanel()
  to create a panel with a default FlowLayout manager
          new JPanel(LayoutManager)
   to create a panel with the specified layout manager.

Use method add(Component)
to add a component to the panel.
For example :
      1. JPanel p = new JPanel();
      2. p.add(new JButton("OK"));
      3.     The following statement places panel p into fram   add(p);
EXAMPLE TESTING PANELS
EVENT AND EVENT SOURCE
 When you run Java GUI programs, the program
 interacts with the user and the events drive its
 execution. An event can be defined as a signal to
 the program that something has happened. Events
 are triggered either by external user actions, such
 as mouse movements, button clicks, and
 keystrokes, or by internal program activities, such
 as a timer. The program can choose to respond to or
 ignore an event.
ADDING EVENT
 JButton jbt = new JButton("OK");
 ActionListener listener = new
 OKListener();
 jbt.addActionListener(this );
SET & GET TEXT :
 getText()
 Returns the string from the text field.
 ex:txt1.getText();

 setText(String text)
Puts the given string in the text field.
 ex:txt1.setText(“MUFIX”);
QUESTIONS ?!!
TASK : CALCULATOR
Thank You

More Related Content

What's hot (8)

Flash Tutorial
Flash TutorialFlash Tutorial
Flash Tutorial
senthil4seo
 
Евгений Обрезков "Behind the terminal"
Евгений Обрезков "Behind the terminal"Евгений Обрезков "Behind the terminal"
Евгений Обрезков "Behind the terminal"
Fwdays
 
The AWT and Swing
The AWT and SwingThe AWT and Swing
The AWT and Swing
adil raja
 
Maya
MayaMaya
Maya
senthil4seo
 
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
GOKUL SREE
 
Lenguaje de programación
Lenguaje de programaciónLenguaje de programación
Lenguaje de programación
aldair fernandez
 
120 tips about_photoshop
120 tips about_photoshop120 tips about_photoshop
120 tips about_photoshop
Galmher
 
Google Earth User Guide
Google Earth User GuideGoogle Earth User Guide
Google Earth User Guide
F Blanco
 
Евгений Обрезков "Behind the terminal"
Евгений Обрезков "Behind the terminal"Евгений Обрезков "Behind the terminal"
Евгений Обрезков "Behind the terminal"
Fwdays
 
The AWT and Swing
The AWT and SwingThe AWT and Swing
The AWT and Swing
adil raja
 
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
GOKUL SREE
 
120 tips about_photoshop
120 tips about_photoshop120 tips about_photoshop
120 tips about_photoshop
Galmher
 
Google Earth User Guide
Google Earth User GuideGoogle Earth User Guide
Google Earth User Guide
F Blanco
 

Viewers also liked (15)

Emerald Ise, Powai - E-Brochure
Emerald Ise, Powai - E-BrochureEmerald Ise, Powai - E-Brochure
Emerald Ise, Powai - E-Brochure
RiteshJuthani
 
NYC Venues
NYC VenuesNYC Venues
NYC Venues
lkittredge
 
20 de março início do outono
20 de março   início do outono20 de março   início do outono
20 de março início do outono
Jesilaine Vinhais
 
Grace tech tool
Grace tech toolGrace tech tool
Grace tech tool
20gball
 
Political.pptpspsls
Political.pptpspslsPolitical.pptpspsls
Political.pptpspsls
tyonnahartsfield
 
Lecture17aam
Lecture17aamLecture17aam
Lecture17aam
deepti0312
 
Assedio moral nas escolas - SEPE
Assedio moral  nas escolas - SEPEAssedio moral  nas escolas - SEPE
Assedio moral nas escolas - SEPE
Adriana De Moraes
 
Getting started with GUI programming in Java_2
Getting started with GUI programming in Java_2Getting started with GUI programming in Java_2
Getting started with GUI programming in Java_2
Muhammad Shebl Farag
 
Cartilha do Servidor Estatutário do Município do RJ/ 2015
Cartilha do Servidor Estatutário do Município do RJ/ 2015Cartilha do Servidor Estatutário do Município do RJ/ 2015
Cartilha do Servidor Estatutário do Município do RJ/ 2015
Adriana De Moraes
 
Módulo 01 - 9 ano- Matemática / Ens.Fundamental
Módulo 01 - 9 ano- Matemática  / Ens.FundamentalMódulo 01 - 9 ano- Matemática  / Ens.Fundamental
Módulo 01 - 9 ano- Matemática / Ens.Fundamental
Adriana De Moraes
 
Avaliação eja 2° período
Avaliação eja 2° períodoAvaliação eja 2° período
Avaliação eja 2° período
Jesilaine Vinhais
 
Avaliação bimestral de ciências 2º e 3º ano - 1º bimestre
Avaliação bimestral de ciências   2º e 3º ano - 1º bimestreAvaliação bimestral de ciências   2º e 3º ano - 1º bimestre
Avaliação bimestral de ciências 2º e 3º ano - 1º bimestre
Jesilaine Vinhais
 
Módulo 01 - 8 ano / Ens.Fundamental
Módulo 01 - 8 ano / Ens.Fundamental  Módulo 01 - 8 ano / Ens.Fundamental
Módulo 01 - 8 ano / Ens.Fundamental
Adriana De Moraes
 
Borang kaji selidik sek
Borang kaji selidik sekBorang kaji selidik sek
Borang kaji selidik sek
Nona Naza
 
Emerald Ise, Powai - E-Brochure
Emerald Ise, Powai - E-BrochureEmerald Ise, Powai - E-Brochure
Emerald Ise, Powai - E-Brochure
RiteshJuthani
 
20 de março início do outono
20 de março   início do outono20 de março   início do outono
20 de março início do outono
Jesilaine Vinhais
 
Grace tech tool
Grace tech toolGrace tech tool
Grace tech tool
20gball
 
Assedio moral nas escolas - SEPE
Assedio moral  nas escolas - SEPEAssedio moral  nas escolas - SEPE
Assedio moral nas escolas - SEPE
Adriana De Moraes
 
Getting started with GUI programming in Java_2
Getting started with GUI programming in Java_2Getting started with GUI programming in Java_2
Getting started with GUI programming in Java_2
Muhammad Shebl Farag
 
Cartilha do Servidor Estatutário do Município do RJ/ 2015
Cartilha do Servidor Estatutário do Município do RJ/ 2015Cartilha do Servidor Estatutário do Município do RJ/ 2015
Cartilha do Servidor Estatutário do Município do RJ/ 2015
Adriana De Moraes
 
Módulo 01 - 9 ano- Matemática / Ens.Fundamental
Módulo 01 - 9 ano- Matemática  / Ens.FundamentalMódulo 01 - 9 ano- Matemática  / Ens.Fundamental
Módulo 01 - 9 ano- Matemática / Ens.Fundamental
Adriana De Moraes
 
Avaliação eja 2° período
Avaliação eja 2° períodoAvaliação eja 2° período
Avaliação eja 2° período
Jesilaine Vinhais
 
Avaliação bimestral de ciências 2º e 3º ano - 1º bimestre
Avaliação bimestral de ciências   2º e 3º ano - 1º bimestreAvaliação bimestral de ciências   2º e 3º ano - 1º bimestre
Avaliação bimestral de ciências 2º e 3º ano - 1º bimestre
Jesilaine Vinhais
 
Módulo 01 - 8 ano / Ens.Fundamental
Módulo 01 - 8 ano / Ens.Fundamental  Módulo 01 - 8 ano / Ens.Fundamental
Módulo 01 - 8 ano / Ens.Fundamental
Adriana De Moraes
 
Borang kaji selidik sek
Borang kaji selidik sekBorang kaji selidik sek
Borang kaji selidik sek
Nona Naza
 
Ad

Similar to Getting started with GUI programming in Java_1 (20)

Lecture 6.pdf
Lecture 6.pdfLecture 6.pdf
Lecture 6.pdf
SakhilejasonMsibi
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
PRN USM
 
Swing
SwingSwing
Swing
Jaydeep Viradiya
 
Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVA
suraj pandey
 
Windows Programming with AWT
Windows Programming with AWTWindows Programming with AWT
Windows Programming with AWT
backdoor
 
Java GUI Programming for beginners-graphics.pdf
Java GUI Programming for beginners-graphics.pdfJava GUI Programming for beginners-graphics.pdf
Java GUI Programming for beginners-graphics.pdf
PBMaverick
 
Swing basics
Swing basicsSwing basics
Swing basics
Medi-Caps University
 
UNIT-I.pptx awt advance java abstract windowing toolkit and swing
UNIT-I.pptx awt advance java abstract windowing toolkit and swingUNIT-I.pptx awt advance java abstract windowing toolkit and swing
UNIT-I.pptx awt advance java abstract windowing toolkit and swing
utkarshabhope
 
Chapter 11.3
Chapter 11.3Chapter 11.3
Chapter 11.3
sotlsoc
 
java swing
java swingjava swing
java swing
Waheed Warraich
 
Session 9_AWT in java with all demonstrations.pdf
Session 9_AWT in java with all demonstrations.pdfSession 9_AWT in java with all demonstrations.pdf
Session 9_AWT in java with all demonstrations.pdf
tabbu23
 
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdfJEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
MarlouFelixIIICunana
 
Chap1 1 1
Chap1 1 1Chap1 1 1
Chap1 1 1
Hemo Chella
 
Chap1 1.1
Chap1 1.1Chap1 1.1
Chap1 1.1
Hemo Chella
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
Adil Mehmoood
 
Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892
renuka gavli
 
Abstract Window Toolkit_Event Handling_python
Abstract Window Toolkit_Event Handling_pythonAbstract Window Toolkit_Event Handling_python
Abstract Window Toolkit_Event Handling_python
jasminebeulahg
 
ch20.pptx
ch20.pptxch20.pptx
ch20.pptx
EnriqueMartinezTelle2
 
13457272.ppt
13457272.ppt13457272.ppt
13457272.ppt
aptechaligarh
 
28 awt
28 awt28 awt
28 awt
Prachi Vijh
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
PRN USM
 
Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVA
suraj pandey
 
Windows Programming with AWT
Windows Programming with AWTWindows Programming with AWT
Windows Programming with AWT
backdoor
 
Java GUI Programming for beginners-graphics.pdf
Java GUI Programming for beginners-graphics.pdfJava GUI Programming for beginners-graphics.pdf
Java GUI Programming for beginners-graphics.pdf
PBMaverick
 
UNIT-I.pptx awt advance java abstract windowing toolkit and swing
UNIT-I.pptx awt advance java abstract windowing toolkit and swingUNIT-I.pptx awt advance java abstract windowing toolkit and swing
UNIT-I.pptx awt advance java abstract windowing toolkit and swing
utkarshabhope
 
Chapter 11.3
Chapter 11.3Chapter 11.3
Chapter 11.3
sotlsoc
 
Session 9_AWT in java with all demonstrations.pdf
Session 9_AWT in java with all demonstrations.pdfSession 9_AWT in java with all demonstrations.pdf
Session 9_AWT in java with all demonstrations.pdf
tabbu23
 
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdfJEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
MarlouFelixIIICunana
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
Adil Mehmoood
 
Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892
renuka gavli
 
Abstract Window Toolkit_Event Handling_python
Abstract Window Toolkit_Event Handling_pythonAbstract Window Toolkit_Event Handling_python
Abstract Window Toolkit_Event Handling_python
jasminebeulahg
 
Ad

Recently uploaded (20)

Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 

Getting started with GUI programming in Java_1

  • 1. GETTING STARTED WITH GUI PROGRAMMING By .Muhammad Shebl
  • 2. OBJECTIVES 1. To create user interfaces using frames. 2. GUI components 3. Adding Component 4. To understand the role of layout managers 5. Panels 6. Actions 7. Set & Get
  • 3. FRAMES  Frame is a window that is not contained inside another window.  Frame is the basis to contain other user interface components in Java GUI applications.  For Swing GUI programs, use JFrame class to create widows.
  • 4. CREATING FRAMES import javax.swing.*; public class Main extends JFrame { public Main() { setSize(200, 150); setTitle("MUFIX"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); } public static void main(String[] args) { Main m=new Main(); } }
  • 5. CENTERING FRAMES By default, a frame is displayed in the upper-left corner of the screen. To display a frame at a specified location, you can use the setLocation(x,y) method in the JFrame class. (0, 0) Screen (x, y) Frame getHeight() screenHeight getWidth() screenWidth
  • 6. CREATING GUI OBJECTS Label Text Check Radio field Box Button Button // Create a button with text OK JButton jbtOK = new JButton("OK"); // Create a label with text "Enter your name: " JLabel jlblName = new JLabel("Enter your name: "); // Create a text field with text "Type Name Here" Combo JTextField jtfName = new JTextField("Type Name Here"); Box // Create a check box with text bold JCheckBox jchkBold = new JCheckBox("Bold"); // Create a radio button with text red JRadioButton jrbRed = new JRadioButton("Red"); // Create a combo box with choices red, green, and blue JComboBox jcboColor = new JComboBox(new String[]{"Red", "Green", "Blue"});
  • 7. LAYOUT MANAGERS  The GUI components are placed in containers. Each container has a layout manager to arrange the GUI components within the container.  Layout managers are set in containers using the setLayout(LayoutManager) method in a container. ◦ FlowLayout ◦ GridLayout ◦ BorderLayout
  • 8. FlowLayout MANAGER The components are arranged in the container from left to right in the order in which they were added. When one row becomes filled, a new row is started. container.setLayout(newFlowLayout(FlowLayout.LEFT,5,5));
  • 9. FlowLayout CONSTRUCTORS  public FlowLayout(int align, int hGap, int vGap) Constructs a new FlowLayout with a specified alignment, horizontal gap, and vertical gap. The gaps are the distances in pixel between components.  public FlowLayout(int alignment) Constructs a new FlowLayout with a specified alignment and a default gap of five pixels for both horizontal and vertical.  public FlowLayout() Constructs a new FlowLayout with a default center alignment and a default gap of five pixels for both horizontal and vertical.
  • 10. GridLayout MANAGER  The GridLayout manager arranges components in a grid (matrix) formation with the number of rows and columns container.setLayout(newGridLayout(3,2,5,5));
  • 11. GridLayout CONSTRUCTORS  public GridLayout(int rows,int columns) Constructs a new GridLayout with the specified number of rows and columns.  public GridLayout(int rows, int columns, int hGap, int vGap) Constructs a new GridLayout with the specified number of rows and columns, along with specified horizontal and vertical gaps between components.
  • 12. BorderLayout MANAGER  The BorderLayout manager divides the container into five areas: East, South, West, North, and Center. container.setLayout(new BorderLayout(5,10)); container.add(jbtOK,BorderLayout.NORTH);
  • 13. USING PANELS AS SUB-CONTAINERS  Panels act as sub-containers for grouping user interface components.  It is recommended that you place the user interface components in panels and place the panels in a frame. You can also place panels in a panel.  To add a component to JFrame, you actually add it to the content pane of JFrame. But to add a component to a panel, you add it directly to the panel using the add method.
  • 14. CREATING A JPanel  You can use  new JPanel() to create a panel with a default FlowLayout manager  new JPanel(LayoutManager) to create a panel with the specified layout manager. Use method add(Component) to add a component to the panel. For example : 1. JPanel p = new JPanel(); 2. p.add(new JButton("OK")); 3. The following statement places panel p into fram add(p);
  • 16. EVENT AND EVENT SOURCE  When you run Java GUI programs, the program interacts with the user and the events drive its execution. An event can be defined as a signal to the program that something has happened. Events are triggered either by external user actions, such as mouse movements, button clicks, and keystrokes, or by internal program activities, such as a timer. The program can choose to respond to or ignore an event.
  • 17. ADDING EVENT  JButton jbt = new JButton("OK");  ActionListener listener = new OKListener(); jbt.addActionListener(this );
  • 18. SET & GET TEXT :  getText() Returns the string from the text field. ex:txt1.getText();  setText(String text) Puts the given string in the text field. ex:txt1.setText(“MUFIX”);