Java Swing - Lecture 1 An Introduction Milena Radenkovic slides originally by Chris Coleman.

Slides:



Advertisements
Similar presentations
G5BUID - Java Swing What is Swing? A part of The Java Foundation Classes Swing Look and feel Accessibility Java 2D (Java 2 onwards) Drag and Drop.
Advertisements

Introduction to Java 2 Programming
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
PHY281Introduction to JavaSlide 1 Introduction to Java In this section we will learn how how to use Java and write our first Java Applet:  The Java Development.
Developing User Interfaces (DUI) Chris North cs3724: HCI.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
GUI Programming in Java
Swing part-one Eriq Muhammad Adams J
Applets, AWTS CompSci 230 Software Construction.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Software Construction Lecture 10 Frameworks
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
Java Swing, Events and MVC Optional Readings: Eckel’s Thinking in Java: Chap 14 (
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Lecture Set 2 Part B – Configuring Visual Studio; Configuration Options and The Help System (scan quickly for future reference)
Chapter 17: Applets, Images, and Sound. Objectives Learn about applets Write an HTML document to host an applet Use the init() method Work with JApplet.
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
Chapter 13. Applets and HTML HTML Applets Computer Programming with JAVA.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Introduction to Applets Course Lecture Slides 29 th July 2010.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 13 : Swing I King Fahd University of Petroleum & Minerals College of Computer Science.
Session 27 Swing vs. AWT. AWT (Abstract Window ToolKit) It is a portable GUI library for stand-alone applications and/or applets. The Abstract Window.
School of Computer Science & Information Technology G6DICP - Lecture 17 GUI (Graphical User Interface) Programming.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Graphics in Java Starring: NetBeans Co-Starring: Java.awt.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Field Trip #19 Animations with Java By Keith Lynn.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
CS Lecture 00 Swing overview and introduction Lynda Thomas
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
1 Java Swing - Lecture 2 Components and Containment Boriana Koleva
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Applets Yong Choi School of Business CSU, Bakersfield.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
CS 4244: Internet Programming User Interface Programming in Java 1.0.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Lecture Model View Controller s/w architecture AND general tips on structuring classes.
Java Swing, Events Readings: Just Java 2: Chap 19 & 21, or Eckel’s Thinking in Java: Chap 14 Slide credits to CMPUT 301, Department of Computing Science.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
Welcome To java
A First Look at GUI Applications
Swing & the JFC – Advanced Java GUI
Ellen Walker Hiram College
Building Graphical User Interface with Swing a short introduction
GUI building with the AWT
Graphical User Interface
Presentation transcript:

Java Swing - Lecture 1 An Introduction Milena Radenkovic slides originally by Chris Coleman

G5BUID - Java Swing Timeline 26 th Oct (Now) - Java Necessaries, Swing Basics 27 th Oct - Components and Containers 3 rd Oct - Layout Management 9 th Nov - Event Handling and Listeners 10 th Nov - Graphics with Swing Java Labs TBA

G5BUID - Java Swing 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

G5BUID - Java Swing 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?

G5BUID - Java Swing D 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…

G5BUID - Java Swing 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

G5BUID - Java Swing On-line reading and reference The Java Swing trail: Swing articles: Developer Technical Articles & Tips:

G5BUID - Java Swing 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

G5BUID - Java Swing Getting started with Swing (1) Compiling & running programs  Swing is standard in Java 2 (JDK >= 1.2)  Use:  ‘javac ’ && ‘java ’  Or JCreator / IDE

G5BUID - Java Swing Getting started with Swing (2) Computer Science Department Stuff…  PCs  Java 2 (1.5.0) on hard disk at \cs\java  Unix (tuck and much):  Java 2 (1.5.0) in /usr/bin (or /usr/java)  Differences between previous versions    Coursework marked on Win XP & JDK 1.5.0

G5BUID - Java Swing 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.*;

G5BUID - Java Swing 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.

G5BUID - Java Swing 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

G5BUID - Java Swing A typical Swing program Consists of multiple parts  Containers  Components  Events  Graphics  (Threads) Now look at each in turn

G5BUID - Java Swing A simple Swing program - Containers Containers

G5BUID - Java Swing 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.

G5BUID - Java Swing A simple Swing program - Components Components

G5BUID - Java Swing 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

G5BUID - Java Swing A simple Swing program - Events Events

G5BUID - Java Swing 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

G5BUID - Java Swing A simple Swing program - Graphics Graphics Complex drawing and shading API. Can do far more than display images.

G5BUID - Java Swing 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.

G5BUID - Java Swing 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

G5BUID - Java Swing 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)

G5BUID - Java Swing 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.

G5BUID - Java Swing How to read Java Docs (1) Java 2 (J2SE 1.5.0) API Reference:  Split into 3 Sections (html frames):  Top Left: Packages  Bottom Left: Classes in Packages  Main Frame: Information about selected Class

G5BUID - Java Swing 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

G5BUID - Java Swing 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