SlideShare a Scribd company logo
GETTING STARTED WITH GUI PROGRAMMING 2


By .Muhammad Shebl
OBJECTIVES
 1.   Labels & Images
 2.   Buttons
 3.   Text Fields & Text Area
 4.   Combo Boxes
 5.   Check box
 6.   Set bounds layout
 7.   Pack() & setResizable()
 8.   Menus
Labels :
 JLabel lab=new JLabel(“MUFIX”);


 ImageIcon icon = new ImageIcon("sigin.png");
JLabel lab=new JLabel(icon );
BUTTONS :
  Adding Event :
 JButton jbt = new JButton("OK");
 jbt.addActionListener(this );


  Add icon image :
  ImageIcon icon = new
    ImageIcon("sigin.png");
 JButton jbt = new JButton(icon);
BUTTONS :
Roll over icon :
   ImageIcon icon = new
    ImageIcon("sigin.png");
 JButton jbt = new JButton(icon);
 Jbt.setRolloverIcon(icon);
BUTTONS:
Roll Pressedicon :


  ImageIcon icon = new
  ImageIcon("sigin.png");
JButton jbt = new JButton(icon);
jbt.setPressedIcon(icon);
TEXT AREA
 If you want to let the user enter multiple
  lines of text, you have to create several
  instances of JTextField. A better alternative
  is to use JTextArea, which enables the user
  to enter multiple lines of text.


 JTextArea jtaNote = new JTextArea(5, 20);
TEXT FIELDS KEY LISTNERS :
// Create a text field with text "Type Name Here"
JTextField jtfName = new JTextField("Type Name Here");


jtfName .addKeyListener(this);
Array of Text Fields
    You can create Array of Text fields by:

    JTextField[][] txt = new JTextField[x][y];

    for (int i = 0; i < x; i++) {

            for (int j = 0; j < y; j++) {

          txt[i][j] = new JTextField(10);

                 panel.add(txt[i][j]);

    txt[i][j].setHorizontalAlignment(JTextField.CENTER);

                 if (i == j) {

                   txt[i][j].setText("1");

                   txt[i][j].setEditable(false);

                 } txt[i][j].addKeyListener(this);

            }}
Combo box
 To Create Combo box :
 JComboBox operations_txt= new JComboBox(new String[]{"<=", "=", ">="});

Operation_txt. getSelectedItem();
Check box :
// Create a check box with text bold
JCheckBox jchkBold = new JCheckBox("Bold");


 jchkBold.addActionListener(new ActionListener() {

       public void actionPerformed(ActionEvent e) {
         if (jchkBold.isSelected()) {
             // your Action
         }
       }
    });
QUESTIONS ?!!
TASK : FULL CALCULATOR
Thank You

More Related Content

PDF
The Ring programming language version 1.5.2 book - Part 63 of 181
PDF
Module 4
PDF
The Ring programming language version 1.5.4 book - Part 66 of 185
PDF
The Ring programming language version 1.6 book - Part 68 of 189
PDF
The Ring programming language version 1.5.1 book - Part 62 of 180
PDF
The Ring programming language version 1.7 book - Part 66 of 196
PDF
The Ring programming language version 1.5.3 book - Part 76 of 184
PDF
The Ring programming language version 1.5.4 book - Part 61 of 185
The Ring programming language version 1.5.2 book - Part 63 of 181
Module 4
The Ring programming language version 1.5.4 book - Part 66 of 185
The Ring programming language version 1.6 book - Part 68 of 189
The Ring programming language version 1.5.1 book - Part 62 of 180
The Ring programming language version 1.7 book - Part 66 of 196
The Ring programming language version 1.5.3 book - Part 76 of 184
The Ring programming language version 1.5.4 book - Part 61 of 185

What's hot (20)

PDF
The Ring programming language version 1.8 book - Part 68 of 202
PDF
The Ring programming language version 1.4.1 book - Part 18 of 31
PDF
The Ring programming language version 1.3 book - Part 44 of 88
PDF
The Ring programming language version 1.3 book - Part 49 of 88
PDF
The Ring programming language version 1.9 book - Part 77 of 210
PDF
The Ring programming language version 1.3 book - Part 43 of 88
PDF
The Ring programming language version 1.10 book - Part 78 of 212
PDF
The Ring programming language version 1.8 book - Part 70 of 202
PDF
The Ring programming language version 1.9 book - Part 71 of 210
PDF
The Ring programming language version 1.5.2 book - Part 64 of 181
PDF
The Ring programming language version 1.5.3 book - Part 70 of 184
PDF
The Ring programming language version 1.8 book - Part 67 of 202
PDF
The Ring programming language version 1.3 book - Part 47 of 88
DOCX
Qtp best tutorial
PDF
The Ring programming language version 1.2 book - Part 46 of 84
PDF
The Ring programming language version 1.4 book - Part 16 of 30
PDF
The Ring programming language version 1.2 book - Part 41 of 84
DOCX
Punto fijo multivariante
PDF
The Ring programming language version 1.10 book - Part 77 of 212
PDF
The Ring programming language version 1.10 book - Part 74 of 212
The Ring programming language version 1.8 book - Part 68 of 202
The Ring programming language version 1.4.1 book - Part 18 of 31
The Ring programming language version 1.3 book - Part 44 of 88
The Ring programming language version 1.3 book - Part 49 of 88
The Ring programming language version 1.9 book - Part 77 of 210
The Ring programming language version 1.3 book - Part 43 of 88
The Ring programming language version 1.10 book - Part 78 of 212
The Ring programming language version 1.8 book - Part 70 of 202
The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.5.2 book - Part 64 of 181
The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.8 book - Part 67 of 202
The Ring programming language version 1.3 book - Part 47 of 88
Qtp best tutorial
The Ring programming language version 1.2 book - Part 46 of 84
The Ring programming language version 1.4 book - Part 16 of 30
The Ring programming language version 1.2 book - Part 41 of 84
Punto fijo multivariante
The Ring programming language version 1.10 book - Part 77 of 212
The Ring programming language version 1.10 book - Part 74 of 212
Ad

Viewers also liked (14)

PDF
Assedio moral nas escolas - SEPE
PPTX
NYC Venues
PPT
Leave management system
PDF
Leave management System
PPTX
RFID Based Student Attendance Management System in India
DOCX
Leave Management System Documentation
PDF
Java Based RFID Attendance Management System Graduation Project Presentation
PPTX
Employee Management System
DOCX
Leave management System
PPTX
Inventory management
DOC
Leave management system chp 1 4
DOCX
Leave Management System: Software Requirements Specification Document(SRS)
PPTX
Inventory Management - a ppt for PGDM/MBA
Assedio moral nas escolas - SEPE
NYC Venues
Leave management system
Leave management System
RFID Based Student Attendance Management System in India
Leave Management System Documentation
Java Based RFID Attendance Management System Graduation Project Presentation
Employee Management System
Leave management System
Inventory management
Leave management system chp 1 4
Leave Management System: Software Requirements Specification Document(SRS)
Inventory Management - a ppt for PGDM/MBA
Ad

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

PPT
Swing basics
PPT
Chapter 5 GUI for introduction of java and gui .ppt
PDF
Getting started with GUI programming in Java_1
PPTX
PDF
Tic Tac Toe game with GUI please dont copy and paste from google. .pdf
PDF
Creating a Facebook Clone - Part XLII.pdf
PDF
Tic Tac Toe game with GUI written in java.SolutionAnswerimp.pdf
PDF
Creating a Facebook Clone - Part XV - Transcript.pdf
PDF
Creating an Uber Clone - Part IX.pdf
PPTX
PPTX
swing_compo.pptxsfdsfffdfdfdfdgwrwrwwtry
PPT
Oop lecture9 10
PPTX
Advanced java programming
PDF
11basic Swing
PPT
Java Swing JFC
PDF
Why am I getting an out of memory error and no window of my .pdf
PPT
011 more swings_adv
PDF
Creating a Facebook Clone - Part XVI.pdf
PDF
Creating a Facebook Clone - Part VII.pdf
PDF
Creating a Facebook Clone - Part XLII - Transcript.pdf
Swing basics
Chapter 5 GUI for introduction of java and gui .ppt
Getting started with GUI programming in Java_1
Tic Tac Toe game with GUI please dont copy and paste from google. .pdf
Creating a Facebook Clone - Part XLII.pdf
Tic Tac Toe game with GUI written in java.SolutionAnswerimp.pdf
Creating a Facebook Clone - Part XV - Transcript.pdf
Creating an Uber Clone - Part IX.pdf
swing_compo.pptxsfdsfffdfdfdfdgwrwrwwtry
Oop lecture9 10
Advanced java programming
11basic Swing
Java Swing JFC
Why am I getting an out of memory error and no window of my .pdf
011 more swings_adv
Creating a Facebook Clone - Part XVI.pdf
Creating a Facebook Clone - Part VII.pdf
Creating a Facebook Clone - Part XLII - Transcript.pdf

Recently uploaded (20)

PPTX
Onica Farming 24rsclub profitable farm business
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PDF
Open folder Downloads.pdf yes yes ges yes
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
Onica Farming 24rsclub profitable farm business
O7-L3 Supply Chain Operations - ICLT Program
NOI Hackathon - Summer Edition - GreenThumber.pptx
Open folder Downloads.pdf yes yes ges yes
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
102 student loan defaulters named and shamed – Is someone you know on the list?
Pharma ospi slides which help in ospi learning
Open Quiz Monsoon Mind Game Final Set.pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Cardiovascular Pharmacology for pharmacy students.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Open Quiz Monsoon Mind Game Prelims.pptx
Revamp in MTO Odoo 18 Inventory - Odoo Slides
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
Abdominal Access Techniques with Prof. Dr. R K Mishra

Getting started with GUI programming in Java_2

  • 1. GETTING STARTED WITH GUI PROGRAMMING 2 By .Muhammad Shebl
  • 2. OBJECTIVES 1. Labels & Images 2. Buttons 3. Text Fields & Text Area 4. Combo Boxes 5. Check box 6. Set bounds layout 7. Pack() & setResizable() 8. Menus
  • 3. Labels :  JLabel lab=new JLabel(“MUFIX”);  ImageIcon icon = new ImageIcon("sigin.png"); JLabel lab=new JLabel(icon );
  • 4. BUTTONS :  Adding Event :  JButton jbt = new JButton("OK");  jbt.addActionListener(this );  Add icon image :  ImageIcon icon = new ImageIcon("sigin.png");  JButton jbt = new JButton(icon);
  • 5. BUTTONS : Roll over icon :  ImageIcon icon = new ImageIcon("sigin.png");  JButton jbt = new JButton(icon);  Jbt.setRolloverIcon(icon);
  • 6. BUTTONS: Roll Pressedicon : ImageIcon icon = new ImageIcon("sigin.png"); JButton jbt = new JButton(icon); jbt.setPressedIcon(icon);
  • 7. TEXT AREA  If you want to let the user enter multiple lines of text, you have to create several instances of JTextField. A better alternative is to use JTextArea, which enables the user to enter multiple lines of text.  JTextArea jtaNote = new JTextArea(5, 20);
  • 8. TEXT FIELDS KEY LISTNERS : // Create a text field with text "Type Name Here" JTextField jtfName = new JTextField("Type Name Here"); jtfName .addKeyListener(this);
  • 9. Array of Text Fields  You can create Array of Text fields by:  JTextField[][] txt = new JTextField[x][y];  for (int i = 0; i < x; i++) {  for (int j = 0; j < y; j++) {  txt[i][j] = new JTextField(10);  panel.add(txt[i][j]); txt[i][j].setHorizontalAlignment(JTextField.CENTER);  if (i == j) {  txt[i][j].setText("1");  txt[i][j].setEditable(false);  } txt[i][j].addKeyListener(this);  }}
  • 10. Combo box  To Create Combo box :  JComboBox operations_txt= new JComboBox(new String[]{"<=", "=", ">="}); Operation_txt. getSelectedItem();
  • 11. Check box : // Create a check box with text bold JCheckBox jchkBold = new JCheckBox("Bold");  jchkBold.addActionListener(new ActionListener() {  public void actionPerformed(ActionEvent e) {  if (jchkBold.isSelected()) {  // your Action  }  }  });
  • 13. TASK : FULL CALCULATOR