SlideShare a Scribd company logo
Java Swing - Lecture 1
An Introduction
Milena Radenkovic
(mvr@cs.nott.ac.uk)
slides originally by Chris Coleman
2
Timeline
• 26th
Oct (Now) - Java Necessaries, Swing Basics
• 27th
Oct - Components and Containers
• 3rd
Oct - Layout Management
• 9th
Nov - Event Handling and Listeners
• 10th
Nov - Graphics with Swing
• Java Labs TBA
3
Before we Start… (1)
• Swing is all Java.
• You must know about, and understand:
 Classes / Objects
 Method Overloading
 Inheritance
 Polymorphism
 Interfaces
 How to read the Java2 API Documents
4
Before We Start… (2)
• If Java is a problem – learn NOW, not later
when the coursework is due!
 Labs
 Come to the labs and help is there for both Java and
Swing.
 Web
 Use the Sun/Java tutorials
 Plenty of web resources out there, even the PRG notes
 Read a book?
5
2D interface programming
toolkits
• Tcl/Tk
• Motif/UIL
• IDEs (e.g. VB, MSVC++/MFC)
• Java AWT – the beginnings
• Java JFC Swing (Java2 - JDK >= 1.2)
• JBuilder and other Java IDEs
• etc…
6
What is Swing?
• A part of The Java Foundation Classes
 Swing
 Look and feel
 Accessibility
 Java 2D (Java 2 onwards)
 Drag and Drop
 etc
• Can be used to build Standalone Apps as well
as Servlets and Applets
7
On-line reading and reference
• The Java Swing trail:
http://java.sun.com/docs/books/tutorial/uiswing/
• Swing articles:
http://java.sun.com/javase/technologies/desktop/articles.jsp
• Developer Technical Articles & Tips:
http://java.sun.com/developer/technicalArticles/GUI/
8
Books
• Java Swing (1998), Robert Eckstein,
Mark Loy, Dave Wood, O'Reilly
• JFC Swing Tutorial, The: A Guide
to Constructing GUIs, 2nd Edition
(2004); K. Walrath and M. Campione,
Addison Wesley
9
Getting started with Swing (1)
• Compiling & running programs
 Swing is standard in Java 2 (JDK >= 1.2)
 Use:
 ‘javac <program.java>’ && ‘java <program>’
 Or JCreator / IDE
10
Getting started with Swing (2)
• Computer Science Department Stuff…
 PCs
 Java 2 (1.5.0) on hard disk at csjava
 Unix (tuck and much):
 Java 2 (1.5.0) in /usr/bin (or /usr/java)
 Differences between previous versions
 http://java.sun.com/j2se/1.4.2/docs/guide/swing/SwingChanges.html
 http://java.sun.com/j2se/1.5.0/docs/guide/swing/SwingChanges.html
 Coursework marked on Win XP & JDK
1.5.0
11
Getting started with Swing (3)
• Swing, like the rest of the Java API is
subdivided into packages:
 javax.swing, javax.accessibility,
javax.swing.border …
• At the start of your code - always
 import javax.swing;
 import javax.swing.event;
• Most Swing programs also need
 import java.awt.*;
 import java.awt.event.*;
12
Differences between Swing and
AWT (1)
• Never mix Swing and AWT components
• If you know AWT, put ‘J’ in front of
everything
 AWT: Button
 Swing: JButton
• Swing does all that AWT does, but better
and there’s much more of it.
13
Differences between Swing and
AWT (2)
• Buttons and labels can display images
• Behaviour and appearance of components
• Component shape
• Borders
• Assistive technologies
• Look and feel of the program’s GUI
 Windows – (but only on Windows, M$ issues….)
 UNIX
 GTK
 etc
14
A typical Swing program
• Consists of multiple parts
 Containers
 Components
 Events
 Graphics
 (Threads)
• Now look at each in turn
15
A simple Swing program -
Containers
• Containers
16
Remember this about
Containers:
• The structure of containers is your design
decision and should always be thought
through in advance
 particularly for managing components
 nesting containers
• Failure to do so usually either results in a
messy interface, messy code or both.
17
A simple Swing program -
Components
• Components
18
Remember this about
Components:
• There are many components that make your job
much easier.
• Often, you will be able to customise an existing
Swing component to do a job for you, instead of
having to start from scratch
 Eg can extend (inherit from) the JButton class and
‘paint’ a new button over the top
19
A simple Swing program -
Events
• Events
20
Remember this about events:
• ‘Events’ as seen by GUIs do not happen
all that often in an application
• Consider what is happening between events
as well as during them
21
A simple Swing program -
Graphics
• Graphics
• Complex drawing and
shading API.
• Can do far more than
display images.
22
Remember this about
Graphics:
• There are many aspects of Swing that
allow you to achieve graphics-like things
without actually using ‘Graphics’.
• Therefore, you don’t have to use them
most of the time, and it is often easier not
to.
23
A simple Swing program -
Threads
• Most simple Swing GUI applications don’t
require use of any (extra) threads
• As Swing creates event-driven programs,
all code is executed on the event-
dispatching thread
24
Remember this about Threads:
The single-thread rule
“Once a Swing component has been realized,
all code that might affect or depend on the
state of that component should be executed in
the event-dispatching thread”
(with some exceptions)
25
How to Learn Swing
• Don’t even try.
• Learn general framework principles and
design styles.
• Then use the API reference, and Swing
Tutorials to discover detailed usage of
each component.
26
How to read Java Docs (1)
• Java 2 (J2SE 1.5.0) API Reference:
 http://java.sun.com/j2se/1.5.0/docs/api/
• Split into 3 Sections (html frames):
 Top Left: Packages
 Bottom Left: Classes in Packages
 Main Frame: Information about selected Class
27
How to read Java Docs (2)
• General idea is find class, and examine main
frame for information.
• Main frame pages split into sections:
 Package hierarchy & implemented interfaces
 Class Description, and links to more info
 Nested Class Summary – Detail in separate page
 Fields - 2 types Class (static) and instance, plus fields
inherited from parent classes / interfaces
 Constructor Summary
 Method Summary & inherited methods from parents
 Detailed info on all summary sections
28
Summary
• Do you know enough Java?
• 2D interface programming toolkits
• JFC/Swing
• AWT and Swing
• Getting started with Swing
• Parts of a simple Swing program
• Tomorrow: Components and Containers
• Some source code, and design styles

More Related Content

What's hot

Java History
Java HistoryJava History
Java History
Prionto Abdullah
 
Java Course 13: JDBC & Logging
Java Course 13: JDBC & LoggingJava Course 13: JDBC & Logging
Java Course 13: JDBC & Logging
Anton Keks
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
Partnered Health
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
Om Ganesh
 
Byte code manipulation and instrumentalization in Java
Byte code manipulation and instrumentalization in JavaByte code manipulation and instrumentalization in Java
Byte code manipulation and instrumentalization in Java
Alex Moskvin
 
Internals of AsyncTask
Internals of AsyncTask Internals of AsyncTask
Internals of AsyncTask
BlrDroid
 
QSpiders - Jdk Jvm Jre and Jit
QSpiders - Jdk Jvm Jre and JitQSpiders - Jdk Jvm Jre and Jit
QSpiders - Jdk Jvm Jre and Jit
Qspiders - Software Testing Training Institute
 
Java Class 2
Java Class 2Java Class 2
Java Class 2
Mayank Aggarwal
 
Java Class1
Java Class1Java Class1
Java Class1
Mayank Aggarwal
 
The Java Story
The Java StoryThe Java Story
The Java Story
David Parsons
 
The Real Thing: Java Virtual Machine
The Real Thing: Java Virtual MachineThe Real Thing: Java Virtual Machine
The Real Thing: Java Virtual Machine
Frontech
 
StudioSL Presentation in Grenoble 2011
StudioSL Presentation in Grenoble 2011StudioSL Presentation in Grenoble 2011
StudioSL Presentation in Grenoble 2011
Enrico Scantamburlo
 

What's hot (13)

Java History
Java HistoryJava History
Java History
 
Java Course 13: JDBC & Logging
Java Course 13: JDBC & LoggingJava Course 13: JDBC & Logging
Java Course 13: JDBC & Logging
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Byte code manipulation and instrumentalization in Java
Byte code manipulation and instrumentalization in JavaByte code manipulation and instrumentalization in Java
Byte code manipulation and instrumentalization in Java
 
Internals of AsyncTask
Internals of AsyncTask Internals of AsyncTask
Internals of AsyncTask
 
java swing
java swingjava swing
java swing
 
QSpiders - Jdk Jvm Jre and Jit
QSpiders - Jdk Jvm Jre and JitQSpiders - Jdk Jvm Jre and Jit
QSpiders - Jdk Jvm Jre and Jit
 
Java Class 2
Java Class 2Java Class 2
Java Class 2
 
Java Class1
Java Class1Java Class1
Java Class1
 
The Java Story
The Java StoryThe Java Story
The Java Story
 
The Real Thing: Java Virtual Machine
The Real Thing: Java Virtual MachineThe Real Thing: Java Virtual Machine
The Real Thing: Java Virtual Machine
 
StudioSL Presentation in Grenoble 2011
StudioSL Presentation in Grenoble 2011StudioSL Presentation in Grenoble 2011
StudioSL Presentation in Grenoble 2011
 

Similar to Java lecture

Java introduction
Java introductionJava introduction
Java introduction
logeswarisaravanan
 
Java review00
Java review00Java review00
Java review00saryu2011
 
JavaFX - Sketch Board to Production
JavaFX - Sketch Board to ProductionJavaFX - Sketch Board to Production
JavaFX - Sketch Board to Production
Yoav Aharoni
 
Java Swing.ppt THIA GIVE YHR BASIC KNOWLEDGER ABOUT JAVA
Java Swing.ppt THIA GIVE YHR BASIC KNOWLEDGER ABOUT JAVAJava Swing.ppt THIA GIVE YHR BASIC KNOWLEDGER ABOUT JAVA
Java Swing.ppt THIA GIVE YHR BASIC KNOWLEDGER ABOUT JAVA
nikitaparmar61
 
Ebook Pdf O Reilly Java Swing
Ebook Pdf    O Reilly   Java SwingEbook Pdf    O Reilly   Java Swing
Ebook Pdf O Reilly Java Swingowambacq
 
Java Swing ppt beginner learning study.ppt
Java Swing ppt beginner learning study.pptJava Swing ppt beginner learning study.ppt
Java Swing ppt beginner learning study.ppt
usha852
 
Joon Cho Java Swing.ppt
Joon Cho Java Swing.pptJoon Cho Java Swing.ppt
Joon Cho Java Swing.ppt
Eyezgaming
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
YounasKhan542109
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
sunmitraeducation
 
java slides
java slidesjava slides
java slides
RizwanTariq18
 
OOP with Java
OOP with JavaOOP with Java
OOP with Java
OmegaHub
 
Introduction to java programming part 1
Introduction to java programming   part 1Introduction to java programming   part 1
Introduction to java programming part 1
university of education,Lahore
 
Java1 in mumbai
Java1 in mumbaiJava1 in mumbai
Java1 in mumbai
vibrantuser
 
Commit to excellence - Java in containers
Commit to excellence - Java in containersCommit to excellence - Java in containers
Commit to excellence - Java in containers
Red Hat Developers
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
Amr Salah
 
Java intro
Java introJava intro
Java intro
husnara mohammad
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_java
Harry Potter
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
James Wong
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
Fraboni Ec
 

Similar to Java lecture (20)

Java introduction
Java introductionJava introduction
Java introduction
 
Java review00
Java review00Java review00
Java review00
 
JavaFX - Sketch Board to Production
JavaFX - Sketch Board to ProductionJavaFX - Sketch Board to Production
JavaFX - Sketch Board to Production
 
Java Swing.ppt THIA GIVE YHR BASIC KNOWLEDGER ABOUT JAVA
Java Swing.ppt THIA GIVE YHR BASIC KNOWLEDGER ABOUT JAVAJava Swing.ppt THIA GIVE YHR BASIC KNOWLEDGER ABOUT JAVA
Java Swing.ppt THIA GIVE YHR BASIC KNOWLEDGER ABOUT JAVA
 
Ebook Pdf O Reilly Java Swing
Ebook Pdf    O Reilly   Java SwingEbook Pdf    O Reilly   Java Swing
Ebook Pdf O Reilly Java Swing
 
Java Swing ppt beginner learning study.ppt
Java Swing ppt beginner learning study.pptJava Swing ppt beginner learning study.ppt
Java Swing ppt beginner learning study.ppt
 
Joon Cho Java Swing.ppt
Joon Cho Java Swing.pptJoon Cho Java Swing.ppt
Joon Cho Java Swing.ppt
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
java slides
java slidesjava slides
java slides
 
OOP with Java
OOP with JavaOOP with Java
OOP with Java
 
Introduction to java programming part 1
Introduction to java programming   part 1Introduction to java programming   part 1
Introduction to java programming part 1
 
Java1 in mumbai
Java1 in mumbaiJava1 in mumbai
Java1 in mumbai
 
Commit to excellence - Java in containers
Commit to excellence - Java in containersCommit to excellence - Java in containers
Commit to excellence - Java in containers
 
Java platform
Java platformJava platform
Java platform
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Java intro
Java introJava intro
Java intro
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_java
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 

Java lecture

  • 1. Java Swing - Lecture 1 An Introduction Milena Radenkovic (mvr@cs.nott.ac.uk) slides originally by Chris Coleman
  • 2. 2 Timeline • 26th Oct (Now) - Java Necessaries, Swing Basics • 27th Oct - Components and Containers • 3rd Oct - Layout Management • 9th Nov - Event Handling and Listeners • 10th Nov - Graphics with Swing • Java Labs TBA
  • 3. 3 Before we Start… (1) • Swing is all Java. • You must know about, and understand:  Classes / Objects  Method Overloading  Inheritance  Polymorphism  Interfaces  How to read the Java2 API Documents
  • 4. 4 Before We Start… (2) • If Java is a problem – learn NOW, not later when the coursework is due!  Labs  Come to the labs and help is there for both Java and Swing.  Web  Use the Sun/Java tutorials  Plenty of web resources out there, even the PRG notes  Read a book?
  • 5. 5 2D interface programming toolkits • Tcl/Tk • Motif/UIL • IDEs (e.g. VB, MSVC++/MFC) • Java AWT – the beginnings • Java JFC Swing (Java2 - JDK >= 1.2) • JBuilder and other Java IDEs • etc…
  • 6. 6 What is Swing? • A part of The Java Foundation Classes  Swing  Look and feel  Accessibility  Java 2D (Java 2 onwards)  Drag and Drop  etc • Can be used to build Standalone Apps as well as Servlets and Applets
  • 7. 7 On-line reading and reference • The Java Swing trail: http://java.sun.com/docs/books/tutorial/uiswing/ • Swing articles: http://java.sun.com/javase/technologies/desktop/articles.jsp • Developer Technical Articles & Tips: http://java.sun.com/developer/technicalArticles/GUI/
  • 8. 8 Books • Java Swing (1998), Robert Eckstein, Mark Loy, Dave Wood, O'Reilly • JFC Swing Tutorial, The: A Guide to Constructing GUIs, 2nd Edition (2004); K. Walrath and M. Campione, Addison Wesley
  • 9. 9 Getting started with Swing (1) • Compiling & running programs  Swing is standard in Java 2 (JDK >= 1.2)  Use:  ‘javac <program.java>’ && ‘java <program>’  Or JCreator / IDE
  • 10. 10 Getting started with Swing (2) • Computer Science Department Stuff…  PCs  Java 2 (1.5.0) on hard disk at csjava  Unix (tuck and much):  Java 2 (1.5.0) in /usr/bin (or /usr/java)  Differences between previous versions  http://java.sun.com/j2se/1.4.2/docs/guide/swing/SwingChanges.html  http://java.sun.com/j2se/1.5.0/docs/guide/swing/SwingChanges.html  Coursework marked on Win XP & JDK 1.5.0
  • 11. 11 Getting started with Swing (3) • Swing, like the rest of the Java API is subdivided into packages:  javax.swing, javax.accessibility, javax.swing.border … • At the start of your code - always  import javax.swing;  import javax.swing.event; • Most Swing programs also need  import java.awt.*;  import java.awt.event.*;
  • 12. 12 Differences between Swing and AWT (1) • Never mix Swing and AWT components • If you know AWT, put ‘J’ in front of everything  AWT: Button  Swing: JButton • Swing does all that AWT does, but better and there’s much more of it.
  • 13. 13 Differences between Swing and AWT (2) • Buttons and labels can display images • Behaviour and appearance of components • Component shape • Borders • Assistive technologies • Look and feel of the program’s GUI  Windows – (but only on Windows, M$ issues….)  UNIX  GTK  etc
  • 14. 14 A typical Swing program • Consists of multiple parts  Containers  Components  Events  Graphics  (Threads) • Now look at each in turn
  • 15. 15 A simple Swing program - Containers • Containers
  • 16. 16 Remember this about Containers: • The structure of containers is your design decision and should always be thought through in advance  particularly for managing components  nesting containers • Failure to do so usually either results in a messy interface, messy code or both.
  • 17. 17 A simple Swing program - Components • Components
  • 18. 18 Remember this about Components: • There are many components that make your job much easier. • Often, you will be able to customise an existing Swing component to do a job for you, instead of having to start from scratch  Eg can extend (inherit from) the JButton class and ‘paint’ a new button over the top
  • 19. 19 A simple Swing program - Events • Events
  • 20. 20 Remember this about events: • ‘Events’ as seen by GUIs do not happen all that often in an application • Consider what is happening between events as well as during them
  • 21. 21 A simple Swing program - Graphics • Graphics • Complex drawing and shading API. • Can do far more than display images.
  • 22. 22 Remember this about Graphics: • There are many aspects of Swing that allow you to achieve graphics-like things without actually using ‘Graphics’. • Therefore, you don’t have to use them most of the time, and it is often easier not to.
  • 23. 23 A simple Swing program - Threads • Most simple Swing GUI applications don’t require use of any (extra) threads • As Swing creates event-driven programs, all code is executed on the event- dispatching thread
  • 24. 24 Remember this about Threads: The single-thread rule “Once a Swing component has been realized, all code that might affect or depend on the state of that component should be executed in the event-dispatching thread” (with some exceptions)
  • 25. 25 How to Learn Swing • Don’t even try. • Learn general framework principles and design styles. • Then use the API reference, and Swing Tutorials to discover detailed usage of each component.
  • 26. 26 How to read Java Docs (1) • Java 2 (J2SE 1.5.0) API Reference:  http://java.sun.com/j2se/1.5.0/docs/api/ • Split into 3 Sections (html frames):  Top Left: Packages  Bottom Left: Classes in Packages  Main Frame: Information about selected Class
  • 27. 27 How to read Java Docs (2) • General idea is find class, and examine main frame for information. • Main frame pages split into sections:  Package hierarchy & implemented interfaces  Class Description, and links to more info  Nested Class Summary – Detail in separate page  Fields - 2 types Class (static) and instance, plus fields inherited from parent classes / interfaces  Constructor Summary  Method Summary & inherited methods from parents  Detailed info on all summary sections
  • 28. 28 Summary • Do you know enough Java? • 2D interface programming toolkits • JFC/Swing • AWT and Swing • Getting started with Swing • Parts of a simple Swing program • Tomorrow: Components and Containers • Some source code, and design styles