Download presentation
Presentation is loading. Please wait.
Published byOsborne Webb Modified over 8 years ago
1
CS12420 - Lecture 00 Swing overview and introduction Lynda Thomas ltt@aber.ac.uk
3
Overview Graphical User Interfaces –The actual graphics, and –Event driven programming (sits there until an event happens) AWT and Swing import java.awt.*; import javax.swing.*; AWT is ABSTRACT Window Toolkit AWT is still used for events etc. but for components….. Swing built on AWT.
4
AWT component classes are older. They communicate with ‘peer’ classes in the underlying OS to use its own components (different for different OSs) –Not all OSs have same components, May not behave exactly the same, so… –Lowest common denominator –Called ‘Heavyweight’ So, Swing was introduced built on AWT. Swing draws its own components, so less communication with OS. –Hence called ‘Lightweight’ –Also wider range of components, more consistency – start ‘J’ Future – JavaFX probably (Java FX Script has been discontinued) DO NOT MIX COMPONENTS don’t use AWT Panel instead of Swing JPanel!!!!! History
5
Links you will need! Java API http://docs.oracle.com/javase/7/docs/api/ Can follow links from the Swing classes to the … (try it with JOptionPane for instance) Swing Tutorial http://docs.oracle.com/javase/tutorial/uiswing/ index.html
6
Using and extending classes You will be using classes like JButton and JTextField You will be extending classes like JFrame (a window) and JPanel (an area in a window)
7
Implementing interfaces You will be implementing interfaces like ActionListener (when a button is pressed) MouseListener (when the mouse is clicked) MouseMotionListener (when the mouse moves)
8
Let’s link to the API and look at a couple of Swing classes that you use or extend See, for instance JButton at http://docs.oracle.com/javase/7/docs/api/ Inheritance hierarchy package help
9
Now look at a Java awt.event interface You have just done interfaces List of methods to be implemented. Have a look at MouseMotionListener Note that it is italic package
10
Your classes will implement these interfaces, so These are the methods to be implemented by you. Read it as ‘in my program when the mouse is dragged do this …’
11
Lectures Today – run Bank and Life just to see what can do. May look at code for ASimple 1.Frames, Panels, Layout, Components 2.Menus 3.Drawing 4.Capturing Mouse information 5.Interactive graphics 6.Patterns - MVC Later… Swing & threads
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.