SlideShare uma empresa Scribd logo
1 de 26
Aarti Narang
Jaskiran Kaur
 Upneet Kaur
A  swing is the primary JAVA GUI widget
  toolkit , an API for providing a GUI for java
  programs.

 Itwas developed to provide a more
  sophisticated set of GUI components Other
  than in AWT package.

 Supports more powerful and flexible
  components that provides advanced and
  pluggable look and feel.
   Platform independent
   Model –View-Controller
   Extensible
   Customizable
   Configurable
   Light weight UI
SWINGS                       AWT

 Light weighted           Heavy weighted
  components.               components.
 Completely written in    Uses of native
  java.                     libraries.
 Better design than       Design issues are still
  AWT.                      not good.
 Own look and feel.       Has to code properly.
 Java.awt.*
 Javax.swing.*




 Javax : hierarchy of packages and set of
 “light weight” components for platform-
 independent rich GUI components.
 JApplet
 JButton
 JCheckBox      Used for making swing applet
 JLabel         instance.

 JComboBox
 JRadioButton
 JScrollPane
 JTabbedPane
 JTable
 JTree
 JTextField
 Swing labels are instances of JLabel class. It
  can display text and/or an icon.

 Constructors   are:
Jlabel(Icon i)
Jlabel(String s,Icon I,int align)

 Methods  are:
Icon getIcon()
String getText()
Void setIcon(Icon i)
Void setText(String s)
Import java.awt.*;
Import javax.swing.*;
/* <applet code=“demo” width=200 height=200> </applet> */
public class demo extends JApplet {

public void init()
{
Container contentPane= getContentPane();

JLabel j1=new JLabel (“HELLO”,i1,JLabel.CENTER);

contentPane.add(j1);
}
}
 Swing image icons are instances of “ImageIcon”
 class, which paints an icon from an image.

 Constructors are:
ImageIcon(URL url)
ImageIcon(String filename)

 Methods  are:
int getIconHeight()
int getIconWidth()
void paintIcon(Component c, Graphics g, int x,int y)
Import java.awt.*;
Import javax.swing.*;
/* <applet code=“demo1” width=200 height=200> </applet> */
public class demo1 extends JApplet {

public void init()
{
Container contentPane= getContentPane();

ImageIcon i1= new ImageIcon(“1.gif”);

JLabel j1=new JLabel (“HELLO”,i1,JLabel.CENTER);

contentPane.add(j1);
}
}
 Swingtext field are instances of
 JTextComponent class. It has one subclass
 “JTextField” , for adding one line of text.

 Constructors   are:
JTextField()
JTextField(int cols)
JTextField(String s,int cols)
JTextField(String s)
Import java.awt.*;
Import javax.swing.*;
/* <applet code=“demo3” width=200 height=200> </applet> */
public class demo3 extends JApplet {

JTextField jtf;

public void init()
{
Container contentPane= getContentPane();

jtf=new JJTextField(20);
contentPane.add(jtf);
}
}
 AbstractButton is a superclass for
  checkboxes, push buttons and radio buttons.
 JButton subclass provides the functionality of a
  push button.

 Constructors   are:
JButton(Icon i)
JButton(String s,Icon i)
JButton(String s)
Import java.awt.*;
Import javax.swing.*;
/* <applet code=“demo2” width=200 height=200> </applet> */
public class demo2 extends JApplet {

public void init()
{
Container contentPane= getContentPane();
ImageIcon img=new ImageIcon(“2.gif”);

JButton jb1=new JButton(img);
contentPane.add(jb1);

JButton jb2=new JButton(“Click here”);
contentPane.add(jb2);
}
}
   JCheckBox class provides the functionality of a
    checkbox. Its immediate superclass is
    JToggleButton, which provides support for two state
    buttons.

 Constructors are:
JCheckBox(Icon i)
JCheckBox(Icon i, Boolean b)
JCheckBox(String s)
JCheckBox(String s, Boolean b)
JCheckBox(String s,Icon i)
JCheckBox(String s,Icon I, Boolean b)

void setSelected(Boolean b)
Import java.awt.*;
Import javax.swing.*;
/* <applet code=“demo4” width=200 height=200> </applet> */
public class demo4 extends JApplet {

public void init()
{
Container contentPane= getContentPane();
JCheckBox cb=new JCheckBox(“C”,true);
contentPane.add(cb);

JCheckBox cb=new JCheckBox(“C++”,normal);
contentPane.add(cb);

JCheckBox cb=new JCheckBox(“Java”,normal);
contentPane.add(cb);
}
}
 Radio  buttons are supported by JRadioButton
  class, a subclass of AbstractButton.
 Constructors are same as of checkboxes.


 Radio
      buttons must be grouped into one set, so
 we use “ButtonGroup” class.

void add(AbstractButton b)
Import java.awt.*;
Import javax.swing.*;
/* <applet code=“demo5” width=200 height=200> </applet> *
public class demo5 extends JApplet {
public void init()
{
Container contentPane= getContentPane();
JRadioButton b1=new JRadioButton(“A”);
contentPane.add(b1);
JRadioButton b2=new JRadioButton(“A”);
contentPane.add(b2);
JRadioButton b3=new JRadioButton(“A”);
contentPane.add(b3);

ButtonGroup bg=new ButtonGroup();
bg.add(b1);
bg.add(b2);
bg.add(b3);
} }
   A tabbed pane is a component that appears as a group of
    folders in a file cabinet. Each folder has title and is
    selected one at a time.
   Tabbed panes are encapsulated by JTabbedPane class.

void addTab(String str, Component comp)

Procedure to use tabbed pane is:

    Create a JTabbedPane object.
    Call addtab() to add a tab to pane(title, and its
    component for each tab).
    Repeat step 2 for each tab.
   Add tabbed pane to content pane of applet.
   Define subclasses for tabs.
public class demo6 extends JApplet {
public void init()
{
JTabbedPane tabs=new JTabbedPane();
Tabs.addTab(“Home”, new homemenu());
Tabs.addTab(“Insert”, new insertmenu());
Tabs.addTab(“View”, new viewmenu());
getContentPane().add(tabs);
}
}
class homemenu extends Jpanel {
public homemenu() {
 ---// buttons
 }}

class insertmenu extends Jpanel {
public insertmenu() {
 ---// radio /checkboxes
 }}
   A scroll pane is a component that presents a rectangular area in
    which a component may be viewed horizontally or vertically.
   Scroll panes are encapsulated by JScrollPane class.

JScrollPane(Component comp)
JScrollPane(int v, int h)
JScrollPane(Component comp, int v, int h)

H and v are constants defined by ScrollPaneConstants
  interface, as follows,

   HORIZONTAL_SCROLLBAR_ALWAYS
   HORIZONTAL_SCROLLBAR_AS_NEEDED
   VERTICAL_SCROLLBAR_ALWAYS
   VERTICAL_SCROLLBAR_AS_NEEDED
public class demo5 extends JApplet {
public void init()
{
Container contentPane= getContentPane();
contentPane.setLayout(new Borderlayout());

Jpanel jp =new Jpanel();
Jp.setLayout(
ButtonGroup bg=new ButtonGroup();
bg.add(b1);
bg.add(b2);
bg.add(b3);
} }
   A check box is a combination of text field and a drop-
    down list.

   Check boxes are provided by JCheckBox class, which
    extends JComponent.

JComboBox()
JComboBox(Vector v)

Here v is a vector that initializes the combo box.

   Items are added to list of choices via a method:
         void addItem(Object obj)

Here obj is the object to be added to the combo box.
public class demo extends JApplet implements ItemListener
 {
public void init()
{
Container contentPane= getContentPane();
JComboBox jc = new JComboBox();
jc.addItem(“Ludhiana”);
jc.addItem(“Chandigarh”);
jc.addItem(“Moga”);
jc.addItemListener (this);
contentPane.add(jc);

JLabel j1 =new JLabel(“ “);
contentPane.add(j1);
}
public void itemStateChanged(ItemEvent e)
 {
String s=(String) i.getItem();
J1.setText(s);
}}
Swings

Mais conteúdo relacionado

Mais procurados

Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in javaAdil Mehmoood
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solutionMazenetsolution
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1PRN USM
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A ReviewFernando Torres
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Javababak danyal
 
Basic using of Swing in Java
Basic using of Swing in JavaBasic using of Swing in Java
Basic using of Swing in Javasuraj pandey
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Javayht4ever
 
Complete java swing
Complete java swingComplete java swing
Complete java swingjehan1987
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART IOXUS 20
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)Bilal Amjad
 
Z blue introduction to gui (39023299)
Z blue   introduction to gui (39023299)Z blue   introduction to gui (39023299)
Z blue introduction to gui (39023299)Narayana Swamy
 

Mais procurados (20)

Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
 
Swing
SwingSwing
Swing
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solution
 
Introdu.awt
Introdu.awtIntrodu.awt
Introdu.awt
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
 
Java swing
Java swingJava swing
Java swing
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A Review
 
Awt and swing in java
Awt and swing in javaAwt and swing in java
Awt and swing in java
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Java
 
Basic using of Swing in Java
Basic using of Swing in JavaBasic using of Swing in Java
Basic using of Swing in Java
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Java
 
Complete java swing
Complete java swingComplete java swing
Complete java swing
 
GUI programming
GUI programmingGUI programming
GUI programming
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
 
GUI Programming with Java
GUI Programming with JavaGUI Programming with Java
GUI Programming with Java
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
 
Swings in java
Swings in javaSwings in java
Swings in java
 
Jdbc
JdbcJdbc
Jdbc
 
Z blue introduction to gui (39023299)
Z blue   introduction to gui (39023299)Z blue   introduction to gui (39023299)
Z blue introduction to gui (39023299)
 

Destaque

Networking Java Socket Programming
Networking Java Socket ProgrammingNetworking Java Socket Programming
Networking Java Socket ProgrammingMousmi Pawar
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming TutorialJignesh Patel
 

Destaque (6)

Java swing
Java swingJava swing
Java swing
 
Networking Java Socket Programming
Networking Java Socket ProgrammingNetworking Java Socket Programming
Networking Java Socket Programming
 
java swing
java swingjava swing
java swing
 
Ppt of socket
Ppt of socketPpt of socket
Ppt of socket
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming Tutorial
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 

Semelhante a Swings

Semelhante a Swings (20)

Unit-2 swing and mvc architecture
Unit-2 swing and mvc architectureUnit-2 swing and mvc architecture
Unit-2 swing and mvc architecture
 
swings.pptx
swings.pptxswings.pptx
swings.pptx
 
Ajp notes-chapter-02
Ajp notes-chapter-02Ajp notes-chapter-02
Ajp notes-chapter-02
 
Swing
SwingSwing
Swing
 
Swing
SwingSwing
Swing
 
Advance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.SwingAdvance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.Swing
 
Chap1 1 1
Chap1 1 1Chap1 1 1
Chap1 1 1
 
Chap1 1.1
Chap1 1.1Chap1 1.1
Chap1 1.1
 
Awt, Swing, Layout managers
Awt, Swing, Layout managersAwt, Swing, Layout managers
Awt, Swing, Layout managers
 
Swing basics
Swing basicsSwing basics
Swing basics
 
Lecture9 oopj
Lecture9 oopjLecture9 oopj
Lecture9 oopj
 
11basic Swing
11basic Swing11basic Swing
11basic Swing
 
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
 
Basic swing
Basic swingBasic swing
Basic swing
 
Chapter iv(modern gui)
Chapter iv(modern gui)Chapter iv(modern gui)
Chapter iv(modern gui)
 
Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1
 
Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892
 
01. introduction to swing
01. introduction to swing01. introduction to swing
01. introduction to swing
 
Advanced java programming
Advanced java programmingAdvanced java programming
Advanced java programming
 
CORE JAVA-2
CORE JAVA-2CORE JAVA-2
CORE JAVA-2
 

Último

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 

Último (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 

Swings

  • 2. A swing is the primary JAVA GUI widget toolkit , an API for providing a GUI for java programs.  Itwas developed to provide a more sophisticated set of GUI components Other than in AWT package.  Supports more powerful and flexible components that provides advanced and pluggable look and feel.
  • 3. Platform independent  Model –View-Controller  Extensible  Customizable  Configurable  Light weight UI
  • 4. SWINGS AWT  Light weighted  Heavy weighted components. components.  Completely written in  Uses of native java. libraries.  Better design than  Design issues are still AWT. not good.  Own look and feel.  Has to code properly.
  • 5.
  • 6.  Java.awt.*  Javax.swing.* Javax : hierarchy of packages and set of “light weight” components for platform- independent rich GUI components.
  • 7.  JApplet  JButton  JCheckBox Used for making swing applet  JLabel instance.  JComboBox  JRadioButton  JScrollPane  JTabbedPane  JTable  JTree  JTextField
  • 8.  Swing labels are instances of JLabel class. It can display text and/or an icon.  Constructors are: Jlabel(Icon i) Jlabel(String s,Icon I,int align)  Methods are: Icon getIcon() String getText() Void setIcon(Icon i) Void setText(String s)
  • 9. Import java.awt.*; Import javax.swing.*; /* <applet code=“demo” width=200 height=200> </applet> */ public class demo extends JApplet { public void init() { Container contentPane= getContentPane(); JLabel j1=new JLabel (“HELLO”,i1,JLabel.CENTER); contentPane.add(j1); } }
  • 10.  Swing image icons are instances of “ImageIcon” class, which paints an icon from an image.  Constructors are: ImageIcon(URL url) ImageIcon(String filename)  Methods are: int getIconHeight() int getIconWidth() void paintIcon(Component c, Graphics g, int x,int y)
  • 11. Import java.awt.*; Import javax.swing.*; /* <applet code=“demo1” width=200 height=200> </applet> */ public class demo1 extends JApplet { public void init() { Container contentPane= getContentPane(); ImageIcon i1= new ImageIcon(“1.gif”); JLabel j1=new JLabel (“HELLO”,i1,JLabel.CENTER); contentPane.add(j1); } }
  • 12.  Swingtext field are instances of JTextComponent class. It has one subclass “JTextField” , for adding one line of text.  Constructors are: JTextField() JTextField(int cols) JTextField(String s,int cols) JTextField(String s)
  • 13. Import java.awt.*; Import javax.swing.*; /* <applet code=“demo3” width=200 height=200> </applet> */ public class demo3 extends JApplet { JTextField jtf; public void init() { Container contentPane= getContentPane(); jtf=new JJTextField(20); contentPane.add(jtf); } }
  • 14.  AbstractButton is a superclass for checkboxes, push buttons and radio buttons.  JButton subclass provides the functionality of a push button.  Constructors are: JButton(Icon i) JButton(String s,Icon i) JButton(String s)
  • 15. Import java.awt.*; Import javax.swing.*; /* <applet code=“demo2” width=200 height=200> </applet> */ public class demo2 extends JApplet { public void init() { Container contentPane= getContentPane(); ImageIcon img=new ImageIcon(“2.gif”); JButton jb1=new JButton(img); contentPane.add(jb1); JButton jb2=new JButton(“Click here”); contentPane.add(jb2); } }
  • 16. JCheckBox class provides the functionality of a checkbox. Its immediate superclass is JToggleButton, which provides support for two state buttons.  Constructors are: JCheckBox(Icon i) JCheckBox(Icon i, Boolean b) JCheckBox(String s) JCheckBox(String s, Boolean b) JCheckBox(String s,Icon i) JCheckBox(String s,Icon I, Boolean b) void setSelected(Boolean b)
  • 17. Import java.awt.*; Import javax.swing.*; /* <applet code=“demo4” width=200 height=200> </applet> */ public class demo4 extends JApplet { public void init() { Container contentPane= getContentPane(); JCheckBox cb=new JCheckBox(“C”,true); contentPane.add(cb); JCheckBox cb=new JCheckBox(“C++”,normal); contentPane.add(cb); JCheckBox cb=new JCheckBox(“Java”,normal); contentPane.add(cb); } }
  • 18.  Radio buttons are supported by JRadioButton class, a subclass of AbstractButton.  Constructors are same as of checkboxes.  Radio buttons must be grouped into one set, so we use “ButtonGroup” class. void add(AbstractButton b)
  • 19. Import java.awt.*; Import javax.swing.*; /* <applet code=“demo5” width=200 height=200> </applet> * public class demo5 extends JApplet { public void init() { Container contentPane= getContentPane(); JRadioButton b1=new JRadioButton(“A”); contentPane.add(b1); JRadioButton b2=new JRadioButton(“A”); contentPane.add(b2); JRadioButton b3=new JRadioButton(“A”); contentPane.add(b3); ButtonGroup bg=new ButtonGroup(); bg.add(b1); bg.add(b2); bg.add(b3); } }
  • 20. A tabbed pane is a component that appears as a group of folders in a file cabinet. Each folder has title and is selected one at a time.  Tabbed panes are encapsulated by JTabbedPane class. void addTab(String str, Component comp) Procedure to use tabbed pane is:  Create a JTabbedPane object.  Call addtab() to add a tab to pane(title, and its component for each tab).  Repeat step 2 for each tab.  Add tabbed pane to content pane of applet.  Define subclasses for tabs.
  • 21. public class demo6 extends JApplet { public void init() { JTabbedPane tabs=new JTabbedPane(); Tabs.addTab(“Home”, new homemenu()); Tabs.addTab(“Insert”, new insertmenu()); Tabs.addTab(“View”, new viewmenu()); getContentPane().add(tabs); } } class homemenu extends Jpanel { public homemenu() { ---// buttons }} class insertmenu extends Jpanel { public insertmenu() { ---// radio /checkboxes }}
  • 22. A scroll pane is a component that presents a rectangular area in which a component may be viewed horizontally or vertically.  Scroll panes are encapsulated by JScrollPane class. JScrollPane(Component comp) JScrollPane(int v, int h) JScrollPane(Component comp, int v, int h) H and v are constants defined by ScrollPaneConstants interface, as follows,  HORIZONTAL_SCROLLBAR_ALWAYS  HORIZONTAL_SCROLLBAR_AS_NEEDED  VERTICAL_SCROLLBAR_ALWAYS  VERTICAL_SCROLLBAR_AS_NEEDED
  • 23. public class demo5 extends JApplet { public void init() { Container contentPane= getContentPane(); contentPane.setLayout(new Borderlayout()); Jpanel jp =new Jpanel(); Jp.setLayout( ButtonGroup bg=new ButtonGroup(); bg.add(b1); bg.add(b2); bg.add(b3); } }
  • 24. A check box is a combination of text field and a drop- down list.  Check boxes are provided by JCheckBox class, which extends JComponent. JComboBox() JComboBox(Vector v) Here v is a vector that initializes the combo box.  Items are added to list of choices via a method: void addItem(Object obj) Here obj is the object to be added to the combo box.
  • 25. public class demo extends JApplet implements ItemListener { public void init() { Container contentPane= getContentPane(); JComboBox jc = new JComboBox(); jc.addItem(“Ludhiana”); jc.addItem(“Chandigarh”); jc.addItem(“Moga”); jc.addItemListener (this); contentPane.add(jc); JLabel j1 =new JLabel(“ “); contentPane.add(j1); } public void itemStateChanged(ItemEvent e) { String s=(String) i.getItem(); J1.setText(s); }}