SlideShare ist ein Scribd-Unternehmen logo
1 von 34
JAVA
Swing
Prepared by
Miss. Arati A. Gadgil
Difference between AWT and Swing
AWT Swing
platform-dependent. platform-independent
heavyweight. lightweight.
doesn't support pluggable look supports pluggable look and
feel. and feel.
provides less components than provides more powerful
Swing. components such as
tables, lists, scrollpanes,
colorchooser,tabbedpane.
2
Methods
public void add(Component c)
public void setSize(int width,int height)
public void setLayout(LayoutManager m)
public void setVisible(boolean b)
3
JButton class
Constructors:
JButton()
JButton(String s)
JButton(Icon i)
Methods
1) public void setText(String s)
2) public String getText()
3) public void setEnabled(boolean b)
4) public void setIcon(Icon b)
5) public Icon getIcon()
6) public void setMnemonic(int a)
7) public void addActionListener(ActionListener a)
4
JRadioButton class
Constructors
JRadioButton()
JRadioButton(String s)
JRadioButton(String s, boolean selected)
Methods
1) public void setText(String s)
2) public String getText()
3) public void setEnabled(boolean b)
4) public void setIcon(Icon b)
5) public Icon getIcon()
6) public void setMnemonic(int a)
7) public void addActionListener(ActionListener a)
5
JTextArea class
Constructors
JTextArea():
JTextArea(String s)
JTextArea(int row, int column)
JTextArea(String s, int row, int column)
Methods
1) public void setRows(int rows)
2) public void setColumns(int cols)
3) public void setFont(Font f)
4) public void insert(String s, int position)
5) public void append(String s)
6
JTable class
Constructors
JTable()
JTable(Object[][] rows, Object[] columns)
7
Graphics class
Methods
public abstract void drawString(String str, int x, int y)
is used to draw the specified string.
public void drawRect(int x, int y, int width, int height)
draws a rectangle with the specified width and height.
public abstract void fillRect(int x, int y, int width, int height)
is used to fill rectangle with the default color and specified width and
height.
public abstract void drawOval(int x, int y, int width, int height)
is used to draw oval with the specified width and height.
public abstract void setFont(Font font)
is used to set the graphics current font to the specified font
8
Methods
public abstract void fillOval(int x, int y, int width, int height)
is used to fill oval with the default color and specified width and
height.
public abstract void drawLine(int x1, int y1, int x2, int y2)
is used to draw line between the points(x1, y1) and (x2, y2).
public abstract void drawArc(int x, int y, int width, int height,
int startAngle, int arcAngle)
is used draw a circular or elliptical arc.
public abstract void fillArc(int x, int y, int width, int height, int
startAngle, int arcAngle)
is used to fill a circular or elliptical arc.
public abstract void setColor(Color c)
is used to set the graphics current color to the specified color. 9
Methods
The following three methods are involved in displaying graphics.
Default versions of each are provided by class Component.
Methods update() and paint() should be redefined to perform the
desired graphics operations.
repaint()
The repaint() method requests that a component be repainted.
public void repaint()
public void repaint(long tm)
public void repaint(int x, int y, int w, int h)
public void repaint(long tm, int x, int y, int w, int h)
10
update()
public void update(Graphics g)
The update() method is called in response to a repaint() request,
or in response to a portion of the component being uncovered or
displayed for the first time.
paint()
public void paint(Graphics g)
The paint() method is called from an update() method, and is responsible
for actually drawing the graphics.
11
JComboBox class
Constructors
JComboBox()
JComboBox(Object[] items)
methods
1)public void addItem(Object anObject):
is used to add an item to the item list.
2) public void removeItem(Object anObject)
is used to delete an item to the item list.
3) public void removeAllItems()
is used to remove all the items from the list.
4) public void setEditable(boolean b)
is used to determine whether the JComboBox is editable.
5) public void addActionListener(ActionListener a)
is used to add the ActionListener.
6) public void addItemListener(ItemListener i)
is used to add the ItemListener.
12
JColorChooser class
Constructors
JColorChooser()
is used to create a color chooser pane with white color initially.
JColorChooser(Color initialColor)
is used to create a color chooser pane with the specified color initially.
Method
public static Color showDialog(Component c, String title, Color
initialColor)
is used to show the color-chooser dialog box.
13
JProgressBar class
Constructors
JProgressBar()
is used to create a horizontal progress bar but no string text.
JProgressBar(int min, int max)
is used to create a horizontal progress bar with the specified minimum
and maximum value.
JProgressBar(int orient)
is used to create a progress bar with the specified orientation, it can be
either Vertical or Horizontal by using SwingConstants.VERTICAL and
SwingConstants.HORIZONTAL constants.
JProgressBar(int orient, int min, int max)
is used to create a progress bar with the specified orientation, minimum
and maximum value 14
Methods
1)public void setStringPainted(boolean b):
is used to determine whether string should be displayed.
2) public void setString(String s)
is used to set value to the progress string.
3) public void setOrientation(int orientation)
is used to set the orientation, it may be either vertical or horizontal
by using SwingConstants. VERTICAL and
SwingConstants.HORIZONTAL constants..
4) public void setValue(int value)
is used to set the current value on the progress bar
15
JSlider class
Constructors
JSlider()
creates a slider with the initial value of 50 and range of 0 to 100.
JSlider(int orientation)
creates a slider with the specified orientation set by either
JSlider.HORIZONTAL or JSlider.VERTICAL with the range 0 to 100
and initial value 50.
JSlider(int min, int max)
creates a horizontal slider using the given min and max.
JSlider(int min, int max, int value): creates a horizontal slider using the
given min, max and value.
JSlider(int orientation, int min, int max, int value): creates a slider using
the given orientation, min, max and value 16
Methods
1)public void setMinorTickSpacing(int n):
is used to set the minor tick spacing to the slider.
2) public void setMajorTickSpacing(int n)
is used to set the major tick spacing to the slider.
3) public void setPaintTicks(boolean b)
is used to determine whether tick marks are painted
4) public void setPaintLabels(boolean b)
is used to determine whether labels are painted.
5) public void setPaintTracks(boolean b)
is used to determine whether track is painted.
17
18
The Model-View-Controller Design Pattern
19
Roots in MVC Swing architecture is rooted in the model-view-controller
( MVC) design that dates back to SmallTalk. MVC architecture calls for
a visual application to be broken up into three separate parts:
• A model that represents the data for the application.
• The view that is the visual representation of that data.
• A controller that takes user input on the view and translates that to
changes in the model.
20
Menus
A menu provides a space-saving way to let the user choose one of
several options. Other components with which the user can make a one-
of-many choice include combo boxes, lists, radio buttons, spinners,
and tool bars.
Creating menu bars
To create a menu bar:
add a JMenuBar to a JFrame
add JMenus to the JMenuBar and
add JMenuItems to the JMenus
21
22
23
24
25
26
27
Pluggable Look and Feel
The Swing toolkit allows you to decide how to configure the particular
look and feel of your application. If you don't specify a look and feel, the
Swing UI manager figures out which one to use.
Leave it up to the Swing UI manager. If a particular look and feel is not
specified by the program, Swing's UI manager checks whether the user
has specified a preference. If that preference hasn't been specified or isn't
available, the default look and feel is used.
The default look and feel is determined by the supplier of the JRE. For
the JRE that Sun provides, the Java look and feel (called Metal) is used.
The Java look and feel works on all platforms.
28
Use the look and feel of the native platform. If the application is
running on a Microsoft Windows XP machine, the Windows look and
feel is used. On Mac OS platforms, the Aqua look and feel is used. On
UNIX platforms, such as Solaris or Linux, either the GTK+ look and feel
or the CDE/Motif look and feel is used, depending on the user's desktop
choice.
Specify a particular look and feel. Swing ships with four look and
feels: Java (also called Metal), Microsoft Windows, GTK+, and
CDE/Motif. The GTK+ look and feel requires a theme, and there are
many available for free on the Internet.
Create your own look and feel using the Synth package.
Use an externally provided look and feel.
29
30
31
32
33
Thank You
34

Weitere ähnliche Inhalte

Was ist angesagt?

Dr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWTDr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWTDrRajeshreeKhande
 
Basic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in JavaBasic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in Javasuraj pandey
 
Basic using of Swing in Java
Basic using of Swing in JavaBasic using of Swing in Java
Basic using of Swing in Javasuraj pandey
 
java-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletjava-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletraksharao
 
Complete java swing
Complete java swingComplete java swing
Complete java swingjehan1987
 
The AWT and Swing
The AWT and SwingThe AWT and Swing
The AWT and Swingadil raja
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Javayht4ever
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in javaAdil Mehmoood
 
AWT Packages , Containers and Components
AWT Packages , Containers and ComponentsAWT Packages , Containers and Components
AWT Packages , Containers and ComponentsSohanur63
 
Advance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.SwingAdvance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.SwingPayal Dungarwal
 

Was ist angesagt? (20)

Dr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWTDr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWT
 
Basic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in JavaBasic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in Java
 
Awt
AwtAwt
Awt
 
Awt controls ppt
Awt controls pptAwt controls ppt
Awt controls ppt
 
Swing
SwingSwing
Swing
 
Basic using of Swing in Java
Basic using of Swing in JavaBasic using of Swing in Java
Basic using of Swing in Java
 
java-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletjava-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of applet
 
java swing
java swingjava swing
java swing
 
Complete java swing
Complete java swingComplete java swing
Complete java swing
 
The AWT and Swing
The AWT and SwingThe AWT and Swing
The AWT and Swing
 
Gui
GuiGui
Gui
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Java
 
Java swing
Java swingJava swing
Java swing
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
 
Java swing
Java swingJava swing
Java swing
 
AWT Packages , Containers and Components
AWT Packages , Containers and ComponentsAWT Packages , Containers and Components
AWT Packages , Containers and Components
 
Advance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.SwingAdvance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.Swing
 
Swings in java
Swings in javaSwings in java
Swings in java
 
Chapter 1 swings
Chapter 1 swingsChapter 1 swings
Chapter 1 swings
 

Andere mochten auch

Andere mochten auch (9)

Applet features
Applet featuresApplet features
Applet features
 
Swing is not dead
Swing is not deadSwing is not dead
Swing is not dead
 
Java Applets
Java AppletsJava Applets
Java Applets
 
Modul Kelas Programming : Java swing (session 2)
Modul Kelas Programming : Java swing (session 2)Modul Kelas Programming : Java swing (session 2)
Modul Kelas Programming : Java swing (session 2)
 
Modul Kelas Programming : Java swing 1
Modul Kelas Programming : Java swing 1Modul Kelas Programming : Java swing 1
Modul Kelas Programming : Java swing 1
 
Applet java
Applet javaApplet java
Applet java
 
Java applets
Java appletsJava applets
Java applets
 
Java applets
Java appletsJava applets
Java applets
 
Java applets
Java appletsJava applets
Java applets
 

Ähnlich wie Java swing

U5 JAVA.pptx
U5 JAVA.pptxU5 JAVA.pptx
U5 JAVA.pptxmadan r
 
Advanced java programming
Advanced java programmingAdvanced java programming
Advanced java programmingKaviya452563
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Appletbackdoor
 
DSJ_Unit III.pdf
DSJ_Unit III.pdfDSJ_Unit III.pdf
DSJ_Unit III.pdfArumugam90
 
PDF ON JAVA - JFC CONCEPT
PDF ON JAVA - JFC CONCEPTPDF ON JAVA - JFC CONCEPT
PDF ON JAVA - JFC CONCEPTNAVYA RAO
 
Java Graphics
Java GraphicsJava Graphics
Java GraphicsShraddha
 
Java applet handouts
Java applet handoutsJava applet handouts
Java applet handoutsiamkim
 
Unit-2 swing and mvc architecture
Unit-2 swing and mvc architectureUnit-2 swing and mvc architecture
Unit-2 swing and mvc architectureAmol Gaikwad
 
ITS-16163-Module 8-Graphic User Interface (GUI)
ITS-16163-Module 8-Graphic User Interface (GUI)ITS-16163-Module 8-Graphic User Interface (GUI)
ITS-16163-Module 8-Graphic User Interface (GUI)oudesign
 
Ajp notes-chapter-02
Ajp notes-chapter-02Ajp notes-chapter-02
Ajp notes-chapter-02Ankit Dubey
 
Computer graphics
Computer graphics Computer graphics
Computer graphics shafiq sangi
 
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_1Muhammad Shebl Farag
 
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYAPYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYAMaulik Borsaniya
 

Ähnlich wie Java swing (20)

U5 JAVA.pptx
U5 JAVA.pptxU5 JAVA.pptx
U5 JAVA.pptx
 
Advanced java programming
Advanced java programmingAdvanced java programming
Advanced java programming
 
Applets
AppletsApplets
Applets
 
13457272.ppt
13457272.ppt13457272.ppt
13457272.ppt
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Applet
 
DSJ_Unit III.pdf
DSJ_Unit III.pdfDSJ_Unit III.pdf
DSJ_Unit III.pdf
 
PDF ON JAVA - JFC CONCEPT
PDF ON JAVA - JFC CONCEPTPDF ON JAVA - JFC CONCEPT
PDF ON JAVA - JFC CONCEPT
 
Java Graphics
Java GraphicsJava Graphics
Java Graphics
 
Applet in java
Applet in javaApplet in java
Applet in java
 
Scmad Chapter07
Scmad Chapter07Scmad Chapter07
Scmad Chapter07
 
Java applet handouts
Java applet handoutsJava applet handouts
Java applet handouts
 
Unit-2 swing and mvc architecture
Unit-2 swing and mvc architectureUnit-2 swing and mvc architecture
Unit-2 swing and mvc architecture
 
GUI.pdf
GUI.pdfGUI.pdf
GUI.pdf
 
L18 applets
L18 appletsL18 applets
L18 applets
 
ITS-16163-Module 8-Graphic User Interface (GUI)
ITS-16163-Module 8-Graphic User Interface (GUI)ITS-16163-Module 8-Graphic User Interface (GUI)
ITS-16163-Module 8-Graphic User Interface (GUI)
 
Ajp notes-chapter-02
Ajp notes-chapter-02Ajp notes-chapter-02
Ajp notes-chapter-02
 
JAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdfJAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdf
 
Computer graphics
Computer graphics Computer graphics
Computer graphics
 
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
 
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYAPYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
 

Mehr von Arati Gadgil (15)

Java adapter
Java adapterJava adapter
Java adapter
 
Java applet
Java appletJava applet
Java applet
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
 
Java stream
Java streamJava stream
Java stream
 
Java thread
Java threadJava thread
Java thread
 
Java networking
Java networkingJava networking
Java networking
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
 
Java package
Java packageJava package
Java package
 
Java interface
Java interfaceJava interface
Java interface
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandling
 
Java exception
Java exception Java exception
Java exception
 
Java collection
Java collectionJava collection
Java collection
 
Java class
Java classJava class
Java class
 
Java basic
Java basicJava basic
Java basic
 

Kürzlich hochgeladen

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
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
 
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
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
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
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 

Kürzlich hochgeladen (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
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
 
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
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
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.
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 

Java swing

  • 2. Difference between AWT and Swing AWT Swing platform-dependent. platform-independent heavyweight. lightweight. doesn't support pluggable look supports pluggable look and feel. and feel. provides less components than provides more powerful Swing. components such as tables, lists, scrollpanes, colorchooser,tabbedpane. 2
  • 3. Methods public void add(Component c) public void setSize(int width,int height) public void setLayout(LayoutManager m) public void setVisible(boolean b) 3
  • 4. JButton class Constructors: JButton() JButton(String s) JButton(Icon i) Methods 1) public void setText(String s) 2) public String getText() 3) public void setEnabled(boolean b) 4) public void setIcon(Icon b) 5) public Icon getIcon() 6) public void setMnemonic(int a) 7) public void addActionListener(ActionListener a) 4
  • 5. JRadioButton class Constructors JRadioButton() JRadioButton(String s) JRadioButton(String s, boolean selected) Methods 1) public void setText(String s) 2) public String getText() 3) public void setEnabled(boolean b) 4) public void setIcon(Icon b) 5) public Icon getIcon() 6) public void setMnemonic(int a) 7) public void addActionListener(ActionListener a) 5
  • 6. JTextArea class Constructors JTextArea(): JTextArea(String s) JTextArea(int row, int column) JTextArea(String s, int row, int column) Methods 1) public void setRows(int rows) 2) public void setColumns(int cols) 3) public void setFont(Font f) 4) public void insert(String s, int position) 5) public void append(String s) 6
  • 8. Graphics class Methods public abstract void drawString(String str, int x, int y) is used to draw the specified string. public void drawRect(int x, int y, int width, int height) draws a rectangle with the specified width and height. public abstract void fillRect(int x, int y, int width, int height) is used to fill rectangle with the default color and specified width and height. public abstract void drawOval(int x, int y, int width, int height) is used to draw oval with the specified width and height. public abstract void setFont(Font font) is used to set the graphics current font to the specified font 8
  • 9. Methods public abstract void fillOval(int x, int y, int width, int height) is used to fill oval with the default color and specified width and height. public abstract void drawLine(int x1, int y1, int x2, int y2) is used to draw line between the points(x1, y1) and (x2, y2). public abstract void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) is used draw a circular or elliptical arc. public abstract void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) is used to fill a circular or elliptical arc. public abstract void setColor(Color c) is used to set the graphics current color to the specified color. 9
  • 10. Methods The following three methods are involved in displaying graphics. Default versions of each are provided by class Component. Methods update() and paint() should be redefined to perform the desired graphics operations. repaint() The repaint() method requests that a component be repainted. public void repaint() public void repaint(long tm) public void repaint(int x, int y, int w, int h) public void repaint(long tm, int x, int y, int w, int h) 10
  • 11. update() public void update(Graphics g) The update() method is called in response to a repaint() request, or in response to a portion of the component being uncovered or displayed for the first time. paint() public void paint(Graphics g) The paint() method is called from an update() method, and is responsible for actually drawing the graphics. 11
  • 12. JComboBox class Constructors JComboBox() JComboBox(Object[] items) methods 1)public void addItem(Object anObject): is used to add an item to the item list. 2) public void removeItem(Object anObject) is used to delete an item to the item list. 3) public void removeAllItems() is used to remove all the items from the list. 4) public void setEditable(boolean b) is used to determine whether the JComboBox is editable. 5) public void addActionListener(ActionListener a) is used to add the ActionListener. 6) public void addItemListener(ItemListener i) is used to add the ItemListener. 12
  • 13. JColorChooser class Constructors JColorChooser() is used to create a color chooser pane with white color initially. JColorChooser(Color initialColor) is used to create a color chooser pane with the specified color initially. Method public static Color showDialog(Component c, String title, Color initialColor) is used to show the color-chooser dialog box. 13
  • 14. JProgressBar class Constructors JProgressBar() is used to create a horizontal progress bar but no string text. JProgressBar(int min, int max) is used to create a horizontal progress bar with the specified minimum and maximum value. JProgressBar(int orient) is used to create a progress bar with the specified orientation, it can be either Vertical or Horizontal by using SwingConstants.VERTICAL and SwingConstants.HORIZONTAL constants. JProgressBar(int orient, int min, int max) is used to create a progress bar with the specified orientation, minimum and maximum value 14
  • 15. Methods 1)public void setStringPainted(boolean b): is used to determine whether string should be displayed. 2) public void setString(String s) is used to set value to the progress string. 3) public void setOrientation(int orientation) is used to set the orientation, it may be either vertical or horizontal by using SwingConstants. VERTICAL and SwingConstants.HORIZONTAL constants.. 4) public void setValue(int value) is used to set the current value on the progress bar 15
  • 16. JSlider class Constructors JSlider() creates a slider with the initial value of 50 and range of 0 to 100. JSlider(int orientation) creates a slider with the specified orientation set by either JSlider.HORIZONTAL or JSlider.VERTICAL with the range 0 to 100 and initial value 50. JSlider(int min, int max) creates a horizontal slider using the given min and max. JSlider(int min, int max, int value): creates a horizontal slider using the given min, max and value. JSlider(int orientation, int min, int max, int value): creates a slider using the given orientation, min, max and value 16
  • 17. Methods 1)public void setMinorTickSpacing(int n): is used to set the minor tick spacing to the slider. 2) public void setMajorTickSpacing(int n) is used to set the major tick spacing to the slider. 3) public void setPaintTicks(boolean b) is used to determine whether tick marks are painted 4) public void setPaintLabels(boolean b) is used to determine whether labels are painted. 5) public void setPaintTracks(boolean b) is used to determine whether track is painted. 17
  • 19. 19 Roots in MVC Swing architecture is rooted in the model-view-controller ( MVC) design that dates back to SmallTalk. MVC architecture calls for a visual application to be broken up into three separate parts: • A model that represents the data for the application. • The view that is the visual representation of that data. • A controller that takes user input on the view and translates that to changes in the model.
  • 20. 20 Menus A menu provides a space-saving way to let the user choose one of several options. Other components with which the user can make a one- of-many choice include combo boxes, lists, radio buttons, spinners, and tool bars. Creating menu bars To create a menu bar: add a JMenuBar to a JFrame add JMenus to the JMenuBar and add JMenuItems to the JMenus
  • 21. 21
  • 22. 22
  • 23. 23
  • 24. 24
  • 25. 25
  • 26. 26
  • 27. 27 Pluggable Look and Feel The Swing toolkit allows you to decide how to configure the particular look and feel of your application. If you don't specify a look and feel, the Swing UI manager figures out which one to use. Leave it up to the Swing UI manager. If a particular look and feel is not specified by the program, Swing's UI manager checks whether the user has specified a preference. If that preference hasn't been specified or isn't available, the default look and feel is used. The default look and feel is determined by the supplier of the JRE. For the JRE that Sun provides, the Java look and feel (called Metal) is used. The Java look and feel works on all platforms.
  • 28. 28 Use the look and feel of the native platform. If the application is running on a Microsoft Windows XP machine, the Windows look and feel is used. On Mac OS platforms, the Aqua look and feel is used. On UNIX platforms, such as Solaris or Linux, either the GTK+ look and feel or the CDE/Motif look and feel is used, depending on the user's desktop choice. Specify a particular look and feel. Swing ships with four look and feels: Java (also called Metal), Microsoft Windows, GTK+, and CDE/Motif. The GTK+ look and feel requires a theme, and there are many available for free on the Internet. Create your own look and feel using the Synth package. Use an externally provided look and feel.
  • 29. 29
  • 30. 30
  • 31. 31
  • 32. 32
  • 33. 33