SlideShare a Scribd company logo
GRAPHICS PROGRAMMING
PROGRAMMAZIONE CONCORRENTE E DISTR.
Università degli Studi di Padova
Dipartimento di Matematica
Corso di Laurea in Informatica, A.A. 2015 – 2016
rcardin@math.unipd.it
Programmazione concorrente e distribuita
SUMMARY
 Introducing Swing
 Main components
 Layout management
 Event handling
2Riccardo Cardin
Programmazione concorrente e distribuita
INTRODUCTION
 A little bit of history
 Java 1.0 refers to the Abstract Window Toolkit (AWT)
for simple GUI programming
 AWT delegates to the underlying OS the responsibility to
create graphical components («peers»)
 Look and feel of target platform
 It was very hard to create high-quality portable GUIs
 Java 1.2 intoduces Swing
 Graphic components are painted onto blank windows
 The only functionality required from the underlying
windowing system is a way to put up windows and to paint
onto them
 Build on top of AWT
3Riccardo Cardin
Programmazione concorrente e distribuita
INTRODUCTION
4Riccardo Cardin
Programmazione concorrente e distribuita
INTRODUCTION
 Swing features
 A little bit slower than AWT
 It’s not a real problem on modern machines
 Rich and convenient set of user interface elements
 Few dependencies on the underlying platform
 Consistent user experience across platforms
 Drawback: different look-and-feel from native GUIs
 Many different look-and-feels (themes)
 Metal, Ocean and Synth (JSE 5.0), Nimbus (JSE 7.0, vector
drawings)
 Package javax.swing: it is considered a Java ext.
5Riccardo Cardin
Programmazione concorrente e distribuita
INTRODUCTION
 Swing Ocean look-and-feel
6Riccardo Cardin
Programmazione concorrente e distribuita
MAIN COMPONENTS
 Frame
 Top level window, Frame (AWT) or JFrame (Swing)
 The only Swing component that is not painted on the canvas
 Always use «J» components, which belong from Swing
7Riccardo Cardin
EventQueue.invokeLater(new Runnable() {
public void run() {
SimpleFrame frame = new SimpleFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
class SimpleFrame extends JFrame {
private static final int DEFAULT_WIDTH = 300;
private static final int DEFAULT_HEIGHT = 200;
public SimpleFrame() {
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
}
}
Programmazione concorrente e distribuita
MAIN COMPONENTS
 Let me explain what’s going on in here...
 By default a frame as size of 0 x 0 pixels, so
SimpleFrame set the size of the frame in its ctor
 You have to define what should happen when the
user closes the application’s frame
 JFrame.EXIT_ON_CLOSE: the program exit on close
 Event dispatch thread
 Finally, a frame has to be made visible, using
setVisible(true)
8Riccardo Cardin
EventQueue.invokeLater(new Runnable() {
public void run() {
// Configuration statement
}
});
You have to do ALWAYS
in this way!!!
Programmazione concorrente e distribuita
MAIN COMPONENTS
 Frame hierarchy
 Component / Windows
 Component is the base class of
every GUI object
 Resize and reshape actions
 Frame properties
 set / get methods
 Toolkit class
 Used to bind some components
to a particular native toolkit impl.
 Adapter pattern
9Riccardo Cardin
Toolkit kit = Toolkit.getDefaultToolkit();
Programmazione concorrente e distribuita
MAIN COMPONENTS
 Display information in a component
 DO NOT DRAW DIRECTLY ONTO A FRAME!
 A frame is considered a container for components
 Use the content pane instead
 Components are instances of JComponent / JPanel
 Implement paintComponent method, that is called by the
event handler every time a window needs to be redrawn
10Riccardo Cardin
// Get the content pane and draw something on it
Container contentPane = frame.getContentPane();
Component c = /* . . . */;
contentPane.add(c);
class MyComponent extends JComponent {
public void paintComponent(Graphics g) {
// code for drawing
}}
Programmazione concorrente e distribuita
MAIN COMPONENTS
11Riccardo Cardin
Used to organize the
menu bar and
content pane and to
implement
look-and-feel
Used to add
Components and to
draw something
onto the frame
Programmazione concorrente e distribuita
MAIN COMPONENTS
12Riccardo Cardin
Programmazione concorrente e distribuita
LAYOUT MANAGEMENT
 JDK has not form designer tools
 You need to write code to position (lay out) the UI
components where you want them to be
 Buttons, text fields, and other UI elements extend the
class Component.
 Components can be placed inside containers, such as panel.
 Containers can themselves be put inside other containers
 Container extends Component
 Composite pattern
13Riccardo Cardin
In general components are placed inside containers, and a layout
manager determines the position and sizes of the components in the
container
Programmazione concorrente e distribuita
LAYOUT MANAGEMENT
14Riccardo Cardin
Container class
stores references to
itself
Programmazione concorrente e distribuita
LAYOUT MANAGEMENT
15Riccardo Cardin
Programmazione concorrente e distribuita
LAYOUT MANAGEMENT
 Composite pattern
 In Swing, the problem is that leaf components are
subclasses of composite class
16Riccardo Cardin
It is a composition
of Component
objects
Programmazione concorrente e distribuita
LAYOUT MANAGEMENT
 Flowlayout
 Elements are put in a row, sized at their preferred size
 Default layout manager for a panel
 If the horizontal space in the container is too small,
the layout uses multiple rows.
 Elements are centered horizontally by default
 Layout changes accordingly to container size
 Constructor permits to specify:
 Left, right or center alignment
 Vertical or horizontal gaps
17Riccardo Cardin
Elements are put in
rows
Programmazione concorrente e distribuita
LAYOUT MANAGEMENT
 Add 3 buttons to a JPanel
18Riccardo Cardin
public class BorderLayoutExample extends JFrame {
public BorderLayoutExample(String title) {
super(title);
// Set the size of the window
setSize(300, 200);
// Add component to frame
addComponentsToPane(getContentPane());
}
private void addComponentsToPane(final Container pane) {
// Panel with FlowLayout as default layout manager
JPanel controls = new JPanel();
controls.add(new JButton("Button 1"));
controls.add(new JButton("Button 2"));
controls.add(new JButton("Button 3"));
// Content pane of the frame, BorderLayout as default
pane.add(controls, BorderLayout.SOUTH);
}
Programmazione concorrente e distribuita
LAYOUT MANAGEMENT
 BorderLayout
 Defines 5 regions in which elements can be placed
 Default layout manager of the JFrame content panel
 BorderLayout.NORTH, BorderLayout.EAST...
 Center is the default position
 The edge components are laid first
 When the container is resized, the dim. of
the edge components are unchanged
 It grows all components to fill the
available space
 Use an intermediate JPanel to contain the
elements
19Riccardo Cardin
Programmazione concorrente e distribuita
LAYOUT MANAGEMENT
 Build a window with 3 buttons at the bottom
20Riccardo Cardin
public class BorderLayoutExample extends JFrame {
public BorderLayoutExample(String title) {
super(title);
// Set the size of the window
setSize(300, 200);
// Add component to frame
addComponentsToPane(getContentPane());
}
private void addComponentsToPane(final Container pane) {
// Panel with FlowLayout as default layout manager
JPanel controls = new JPanel();
controls.add(new JButton("Button 1"));
controls.add(new JButton("Button 2"));
controls.add(new JButton("Button 3"));
// Content pane of the frame, BorderLayout as default
pane.add(controls, BorderLayout.SOUTH);
}
Programmazione concorrente e distribuita
LAYOUT MANAGEMENT
 GridLayout
 Arranges all components in rows and columns like a
spreadsheet
 All components are given the same size (also in case of
resizing of the window)
 Usually used to model a small part of a UI, rather than the
whole windows
 Components are added starting from the first entry in
the first row, then the second entry and so on
21Riccardo Cardin
// Get the content pane and draw something on it
// Valuing with a 0 the number of rows will allow the layout to
// use as many rows as necessary
panel.setLayout(new GridLayout(4, 4));
Programmazione concorrente e distribuita
LAYOUT MANAGEMENT
 Build a windows with 4 buttons put in 2 rows
22Riccardo Cardin
public class GridLayoutExample extends JFrame {
public BorderLayoutExample(String title) {
super(title);
// Set the size of the window
setSize(300, 200);
// Add component to frame
addComponentsToPane(getContentPane());
}
private void addComponentsToPane(final Container pane) {
// Set GridLayout to the panelb
JPanel controls = new JPanel();
controls.setLayout(new GridLayout(2, 2));
controls.add(new JButton("Button 1"));
controls.add(new JButton("Button 2"));
controls.add(new JButton("Button 3"));
controls.add(new JButton("Button 4"));
pane.add(controls;
}
Programmazione concorrente e distribuita
LAYOUT MANAGEMENT
 CardLayout
 Used to model two or more components that share
the same display space
 It is like playing card in a stack, where only the top
card (component) is visible at any time
 You can ask for either the first or the last card
 You can ask to flip the deck backwards or forwards
 You can specify a card with a specific name
23Riccardo Cardin
Programmazione concorrente e distribuita
LAYOUT MANAGEMENT
 Build a window with two cards
24Riccardo Cardin
public class CardLayoutExample extends JFrame {
// ...
private void addComponentsToPane(final Container pane) {
// ...
cards = new JPanel(new CardLayout());
cards.add(createCard1(), "Card 1");
cards.add(createCard2(), "Card 2");
}
private JPanel createCombo() {
// ...
// Add combo a listener
comboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
// Get the layout
CardLayout layuot = (CardLayout) cards.getLayout();
layuot.show(cards, (String) e.getItem());
}
});
We will introduce
listeners in a
moment
Programmazione concorrente e distribuita
LAYOUT MANAGEMENT
25Riccardo Cardin
Programmazione concorrente e distribuita
EVENT HANDLING
 An operating environment constantly monitors
events and reports them to the program
 The program decides what to do in response to these
events
 Keystrokes, mouse clicks, and so on
 In Java (AWT) the developer has the full control on
how the events are transmitted from the event
source to events listeners
 Every object can be an event listener (delegation model)
 Event listeners register themself to an event source
 Obsever pattern
 Events are objects of type java.util.EventObject
26Riccardo Cardin
Programmazione concorrente e distribuita
EVENT HANDLING
 Summarizing
 A listener object implements a listener interface
 An event source can register listener and send them
event objects
 The event source sends events to every registered
listener
 The listener, using the event info, reacts accordingly
27Riccardo Cardin
class MyListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
// React to the event goes here
}
}
JButton button = new Jbutton("OK");
button.addActionListener(listener); // Registering a listener
Programmazione concorrente e distribuita
EVENT HANDLING
28Riccardo Cardin
An event source
registers a listener
Event
source
Event source notifies
the listener
The listener react
accordingly
Programmazione concorrente e distribuita
EVENT HANDLING
29Riccardo Cardin
Programmazione concorrente e distribuita
EVENT HANDLING
30Riccardo Cardin
Programmazione concorrente e distribuita
EVENT HANDLING
 Let’s see a simple example
 First of all, let’s create the buttons
 To create a button, simply create a JButton object, giving to
it a label or an icon
31Riccardo Cardin
We will show a panel populated with three buttons. When a button is
clicked, we want the background color of the panel to change to a
particular color.
// Create the buttons
JButton blueButton = new JButton("Yellow");
JButton blueButton = new JButton("Blue");
JButton redButton = new JButton("Red");
// Add them to a panel (flow layout anyone?)
buttonPanel.add(yellowButton);
buttonPanel.add(blueButton);
buttonPanel.add(redButton);
Programmazione concorrente e distribuita
EVENT HANDLING
 Let’s see a simple example
 Then, let’s define button listeners
32Riccardo Cardin
class ColorAction implements ActionListener {
private Color backgroundColor; // The color to set to the panel
public ColorAction(Color c) {
backgroundColor = c;
}
public void actionPerformed(ActionEvent event) {
// set panel background color
}
}
// Create the listeners
ColorAction yellowAction = new ColorAction(Color.YELLOW);
ColorAction blueAction = new ColorAction(Color.BLUE);
ColorAction redAction = new ColorAction(Color.RED);
// Register listeners to buttons
yellowButton.addActionListener(yellowAction);
blueButton.addActionListener(blueAction);
redButton.addActionListener(redAction);
Programmazione concorrente e distribuita
EVENT HANDLING
 Let’s see a simple example
 A problem rises: how can a listener modify a property
of the panel?
 Please, do not try to add listener’s func. to the frame
 Violation of separation of concerns
 Use inner classes instead!
33Riccardo Cardin
class ButtonFrame extends JFrame {
// The panel to change the color
private JPanel buttonPanel;
private class ColorAction implements ActionListener {
private Color backgroundColor;
public void actionPerformed(ActionEvent event) {
// Changing the color to the main class panel
buttonPanel.setBackground(backgroundColor);
}
}
}
Programmazione concorrente e distribuita
EVENT HANDLING
 Let’s see a simple example
 Can we go even further?
 Let’s use anonymous inner classes to handle events
 The inner class mechanism automatically generates a
constructor that stores all final variables that are used
 Closure anyone?!
34Riccardo Cardin
public void makeButton(String name, final Color backgroundColor) {
JButton button = new JButton(name);
buttonPanel.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
buttonPanel.setBackground(backgroundColor);
}
});
}
Programmazione concorrente e distribuita
EVENT HANDLING
35Riccardo Cardin
Programmazione concorrente e distribuita
EVENT HANDLING
 Let’s see a simple example
 If the anonymous inner class method calls one
method only, EventHandler class can be used
 Reflection mechanism
 The statement frame.loadData() is executed in response
of an event
 The statement
frame.loadData(event.getSource.getText()) is
executed
36Riccardo Cardin
loadButton.addActionListener(
EventHandler.create(ActionListener.class, frame, "loadData"));
EventHandler.create(ActionListener.class, frame, "loadData",
"source.text");
Programmazione concorrente e distribuita
EVENT HANDLING
 Not all events are simply as button clicks
 The listener WindowListener interface, that handles
WindowEvent objects, has 7 methods
 Probably you don’t need to defined them all!
 Each AWT listener interfaces with more than one
method comes with a companion Adapter
 Implements all methods with "do nothing" operations
37Riccardo Cardin
public interface WindowListener {
void windowOpened(WindowEvent e);
void windowClosing(WindowEvent e);
void windowClosed(WindowEvent e);
void windowIconified(WindowEvent e);
void windowDeiconified(WindowEvent e);
void windowActivated(WindowEvent e);
void windowDeactivated(WindowEvent e);
}
Programmazione concorrente e distribuita
EVENT HANDLING
 Adapter pattern
 Class adapter
 Object adapter
38Riccardo Cardin
Target interface
Source interface
Adapt source interface
to target
Programmazione concorrente e distribuita
EVENT HANDLING
 What if you need to share the same behaviour
in response to more than one event?
 Use Action interface, that extends ActionListener
 It encapsulates the description of the «command» and
parameters that are necessary to carry out the command
 Command pattern
 AbstractAction is an adapter class provided by the JDK
 Then simply add the action to your UI components using
constructor
39Riccardo Cardin
void actionPerformed(ActionEvent event)
// Add a property to the action object indexed by key
void putValue(String key, Object value)
// Get a property indexed by key
Object getValue(String key)
new JButton(new MyAction());
Programmazione concorrente e distribuita
EVENT HANDLING
Interface Method Params Generated by
ActionListener actionPerformed ActionEvent
• getActionCommand
• getModifiers
ActionButton
JComboBox
JTextField
Timer
AdjustmentListener adjustementValueChang
ed
AdjustementEvent
• getAdjustable
• getAdjustableType
• getValue
JScrollbar
ItemListener itemStateChanged ItemEvent
• getItem
• getItemSelectable
• getStateChange
AbstractButton
JComboBox
FocusListener focusGained
focusLost
FocusEvent
• isTemporary
Component
KeyListener keyPressed
keyReleased
keyTyped
KeyEvent
• getKeyChar
• getKeyCode
• getKeyModifiersText
• getKeyText
• isActionKey
Component
40Riccardo Cardin
Programmazione concorrente e distribuita
EVENT HANDLING
...and so on
41Riccardo Cardin
Interface Method Params Generated by
MouseListener mousePressed
mouseReleased
mouseEntered
mouseExited
mouseClicked
MouseEvent
• getClickCount
• getX
• getY
• getPoint
• translatePoint
Component
MouseMotionListener mouseDragged
mouseMoved
MouseEvent Component
MouseWheelListener mouseWheelMoved MouseWheelEvent
• getWheelRotation
• getScrollAmount
Component
WindowListener windowClosing
windowOpened
windowIconified
windowDeiconified
windowClosed
windowActivated
windowDeactivated
WindowEvent
• getWindow
Window
Programmazione concorrente e distribuita
CONCLUSIONS
42Riccardo Cardin
Programmazione concorrente e distribuita
EXAMPLES
43Riccardo Cardin
https://github.com/rcardin/pcd-snippets
Programmazione concorrente e distribuita
REFERENCES
 Chap. 7 «Graphics Programming», Core Java Volume I -
Fundamentals, Cay Horstmann, Gary Cornell, 2012, Prentice Hall
 Chap. 8 «Event Handling», Core Java Volume I - Fundamentals, Cay
Horstmann, Gary Cornell, 2012, Prentice Hall
 Chap. 9 «User Interface Components with Swing», Core Java
Volume I - Fundamentals, Cay Horstmann, Gary Cornell, 2012,
Prentice Hall
 How to Use FlowLayout
https://docs.oracle.com/javase/tutorial/uiswing/layout/flow.html
 How to Use CardLayout
https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html
 How to Use Actions
https://docs.oracle.com/javase/tutorial/uiswing/misc/action.html
44Riccardo Cardin

More Related Content

What's hot

Module 2: C# 3.0 Language Enhancements (Material)
Module 2: C# 3.0 Language Enhancements (Material)Module 2: C# 3.0 Language Enhancements (Material)
Module 2: C# 3.0 Language Enhancements (Material)
Mohamed Saleh
 
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Akhil Mittal
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My Heart
Bui Kiet
 
Vlsi cadence tutorial_ahmet_ilker_şin
Vlsi cadence tutorial_ahmet_ilker_şinVlsi cadence tutorial_ahmet_ilker_şin
Vlsi cadence tutorial_ahmet_ilker_şin
ilker Şin
 
Big Java Chapter 1
Big Java Chapter 1Big Java Chapter 1
Big Java Chapter 1
Maria Joslin
 
Shape12 6
Shape12 6Shape12 6
Shape12 6pslulli
 
Applets in java
Applets in javaApplets in java
Applets in java
Wani Zahoor
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
ciklum_ods
 
VLSI lab report using Cadence tool
VLSI lab report using Cadence toolVLSI lab report using Cadence tool
VLSI lab report using Cadence tool
Maharaja Institute of Technology Mysore
 
Aptitute question papers in c
Aptitute question papers in cAptitute question papers in c
Aptitute question papers in c
Pantech ProEd Pvt Ltd
 
Simware Simdeveloper
Simware SimdeveloperSimware Simdeveloper
Simware Simdeveloper
José Ramón Martínez Salio
 
Applet life cycle
Applet life cycleApplet life cycle
GCC RTL and Machine Description
GCC RTL and Machine DescriptionGCC RTL and Machine Description
GCC RTL and Machine Description
Priyatham Bollimpalli
 
[Apostila] programação arduíno brian w. evans
[Apostila] programação arduíno   brian w. evans[Apostila] programação arduíno   brian w. evans
[Apostila] programação arduíno brian w. evans
Web-Desegner
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
suraj pandey
 
Design functional solutions in Java, a practical example
Design functional solutions in Java, a practical exampleDesign functional solutions in Java, a practical example
Design functional solutions in Java, a practical example
Marian Wamsiedel
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Java
yht4ever
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
PRN USM
 

What's hot (20)

Module 2: C# 3.0 Language Enhancements (Material)
Module 2: C# 3.0 Language Enhancements (Material)Module 2: C# 3.0 Language Enhancements (Material)
Module 2: C# 3.0 Language Enhancements (Material)
 
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My Heart
 
Vlsi cadence tutorial_ahmet_ilker_şin
Vlsi cadence tutorial_ahmet_ilker_şinVlsi cadence tutorial_ahmet_ilker_şin
Vlsi cadence tutorial_ahmet_ilker_şin
 
Big Java Chapter 1
Big Java Chapter 1Big Java Chapter 1
Big Java Chapter 1
 
Shape12 6
Shape12 6Shape12 6
Shape12 6
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
VLSI lab report using Cadence tool
VLSI lab report using Cadence toolVLSI lab report using Cadence tool
VLSI lab report using Cadence tool
 
Aptitute question papers in c
Aptitute question papers in cAptitute question papers in c
Aptitute question papers in c
 
Simware Simdeveloper
Simware SimdeveloperSimware Simdeveloper
Simware Simdeveloper
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
GCC RTL and Machine Description
GCC RTL and Machine DescriptionGCC RTL and Machine Description
GCC RTL and Machine Description
 
[Apostila] programação arduíno brian w. evans
[Apostila] programação arduíno   brian w. evans[Apostila] programação arduíno   brian w. evans
[Apostila] programação arduíno brian w. evans
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
 
Design functional solutions in Java, a practical example
Design functional solutions in Java, a practical exampleDesign functional solutions in Java, a practical example
Design functional solutions in Java, a practical example
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Java
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
 
GUI Programming with Java
GUI Programming with JavaGUI Programming with Java
GUI Programming with Java
 

Viewers also liked

Software architecture patterns
Software architecture patternsSoftware architecture patterns
Software architecture patterns
Riccardo Cardin
 
Design Pattern Architetturali - Dependency Injection
Design Pattern Architetturali - Dependency InjectionDesign Pattern Architetturali - Dependency Injection
Design Pattern Architetturali - Dependency Injection
Riccardo Cardin
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
Riccardo Cardin
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
Bozhidar Bozhanov
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
Riccardo Cardin
 
Java - Sockets
Java - SocketsJava - Sockets
Java - Sockets
Riccardo Cardin
 
Errori comuni nei documenti di Analisi dei Requisiti
Errori comuni nei documenti di Analisi dei RequisitiErrori comuni nei documenti di Analisi dei Requisiti
Errori comuni nei documenti di Analisi dei Requisiti
Riccardo Cardin
 
Diagrammi delle Classi
Diagrammi delle ClassiDiagrammi delle Classi
Diagrammi delle Classi
Riccardo Cardin
 
Introduzione ai Design Pattern
Introduzione ai Design PatternIntroduzione ai Design Pattern
Introduzione ai Design Pattern
Riccardo Cardin
 
Java - Concurrent programming - Thread's basics
Java - Concurrent programming - Thread's basicsJava - Concurrent programming - Thread's basics
Java - Concurrent programming - Thread's basics
Riccardo Cardin
 
Diagrammi di Sequenza
Diagrammi di SequenzaDiagrammi di Sequenza
Diagrammi di Sequenza
Riccardo Cardin
 
Presto updates to 0.178
Presto updates to 0.178Presto updates to 0.178
Presto updates to 0.178
Kai Sasaki
 
Design Pattern Strutturali
Design Pattern StrutturaliDesign Pattern Strutturali
Design Pattern Strutturali
Riccardo Cardin
 
Scala For Java Programmers
Scala For Java ProgrammersScala For Java Programmers
Scala For Java Programmers
Enno Runne
 
Java - Remote method invocation
Java - Remote method invocationJava - Remote method invocation
Java - Remote method invocation
Riccardo Cardin
 
Java- Concurrent programming - Synchronization (part 1)
Java- Concurrent programming - Synchronization (part 1)Java- Concurrent programming - Synchronization (part 1)
Java- Concurrent programming - Synchronization (part 1)
Riccardo Cardin
 
Java- Concurrent programming - Synchronization (part 2)
Java- Concurrent programming - Synchronization (part 2)Java- Concurrent programming - Synchronization (part 2)
Java- Concurrent programming - Synchronization (part 2)
Riccardo Cardin
 
A (too) Short Introduction to Scala
A (too) Short Introduction to ScalaA (too) Short Introduction to Scala
A (too) Short Introduction to Scala
Riccardo Cardin
 
Design pattern architetturali Model View Controller, MVP e MVVM
Design pattern architetturali   Model View Controller, MVP e MVVMDesign pattern architetturali   Model View Controller, MVP e MVVM
Design pattern architetturali Model View Controller, MVP e MVVM
Riccardo Cardin
 
Java Exception Handling, Assertions and Logging
Java Exception Handling, Assertions and LoggingJava Exception Handling, Assertions and Logging
Java Exception Handling, Assertions and Logging
Riccardo Cardin
 

Viewers also liked (20)

Software architecture patterns
Software architecture patternsSoftware architecture patterns
Software architecture patterns
 
Design Pattern Architetturali - Dependency Injection
Design Pattern Architetturali - Dependency InjectionDesign Pattern Architetturali - Dependency Injection
Design Pattern Architetturali - Dependency Injection
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 
Java - Sockets
Java - SocketsJava - Sockets
Java - Sockets
 
Errori comuni nei documenti di Analisi dei Requisiti
Errori comuni nei documenti di Analisi dei RequisitiErrori comuni nei documenti di Analisi dei Requisiti
Errori comuni nei documenti di Analisi dei Requisiti
 
Diagrammi delle Classi
Diagrammi delle ClassiDiagrammi delle Classi
Diagrammi delle Classi
 
Introduzione ai Design Pattern
Introduzione ai Design PatternIntroduzione ai Design Pattern
Introduzione ai Design Pattern
 
Java - Concurrent programming - Thread's basics
Java - Concurrent programming - Thread's basicsJava - Concurrent programming - Thread's basics
Java - Concurrent programming - Thread's basics
 
Diagrammi di Sequenza
Diagrammi di SequenzaDiagrammi di Sequenza
Diagrammi di Sequenza
 
Presto updates to 0.178
Presto updates to 0.178Presto updates to 0.178
Presto updates to 0.178
 
Design Pattern Strutturali
Design Pattern StrutturaliDesign Pattern Strutturali
Design Pattern Strutturali
 
Scala For Java Programmers
Scala For Java ProgrammersScala For Java Programmers
Scala For Java Programmers
 
Java - Remote method invocation
Java - Remote method invocationJava - Remote method invocation
Java - Remote method invocation
 
Java- Concurrent programming - Synchronization (part 1)
Java- Concurrent programming - Synchronization (part 1)Java- Concurrent programming - Synchronization (part 1)
Java- Concurrent programming - Synchronization (part 1)
 
Java- Concurrent programming - Synchronization (part 2)
Java- Concurrent programming - Synchronization (part 2)Java- Concurrent programming - Synchronization (part 2)
Java- Concurrent programming - Synchronization (part 2)
 
A (too) Short Introduction to Scala
A (too) Short Introduction to ScalaA (too) Short Introduction to Scala
A (too) Short Introduction to Scala
 
Design pattern architetturali Model View Controller, MVP e MVVM
Design pattern architetturali   Model View Controller, MVP e MVVMDesign pattern architetturali   Model View Controller, MVP e MVVM
Design pattern architetturali Model View Controller, MVP e MVVM
 
Java Exception Handling, Assertions and Logging
Java Exception Handling, Assertions and LoggingJava Exception Handling, Assertions and Logging
Java Exception Handling, Assertions and Logging
 

Similar to Java Graphics Programming

Swing
SwingSwing
L11cs2110sp13
L11cs2110sp13L11cs2110sp13
L11cs2110sp13
karan saini
 
Abstract Window Toolkit
Abstract Window ToolkitAbstract Window Toolkit
Abstract Window Toolkit
RutvaThakkar1
 
Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892
renuka gavli
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
Adil Mehmoood
 
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdfJEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
MarlouFelixIIICunana
 
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
 
Chap1 1 1
Chap1 1 1Chap1 1 1
Chap1 1 1
Hemo Chella
 
Chap1 1.1
Chap1 1.1Chap1 1.1
Chap1 1.1
Hemo Chella
 
Java GUI Programming for beginners-graphics.pdf
Java GUI Programming for beginners-graphics.pdfJava GUI Programming for beginners-graphics.pdf
Java GUI Programming for beginners-graphics.pdf
PBMaverick
 
Session2-J2ME development-environment
Session2-J2ME development-environmentSession2-J2ME development-environment
Session2-J2ME development-environment
muthusvm
 
Md10 building java gu is
Md10 building java gu isMd10 building java gu is
Md10 building java gu isRakesh Madugula
 
UNIT-2-AJAVA.pdf
UNIT-2-AJAVA.pdfUNIT-2-AJAVA.pdf
UNIT-2-AJAVA.pdf
PriyanshiPrajapati27
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
James Williams
 
Working with the Calculator program Once imported run the.pdf
Working with the Calculator program Once imported  run the.pdfWorking with the Calculator program Once imported  run the.pdf
Working with the Calculator program Once imported run the.pdf
iconsystemsslm
 
08graphics
08graphics08graphics
08graphics
Waheed Warraich
 
User Guide of Regression Test & Validation Tool (v1.0)
User Guide of Regression Test & Validation Tool (v1.0)User Guide of Regression Test & Validation Tool (v1.0)
User Guide of Regression Test & Validation Tool (v1.0)Chen Fang
 
java swing
java swingjava swing
java swing
Waheed Warraich
 

Similar to Java Graphics Programming (20)

Swing
SwingSwing
Swing
 
L11cs2110sp13
L11cs2110sp13L11cs2110sp13
L11cs2110sp13
 
Abstract Window Toolkit
Abstract Window ToolkitAbstract Window Toolkit
Abstract Window Toolkit
 
Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
 
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdfJEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
 
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
 
Chap1 1 1
Chap1 1 1Chap1 1 1
Chap1 1 1
 
Chap1 1.1
Chap1 1.1Chap1 1.1
Chap1 1.1
 
swingbasics
swingbasicsswingbasics
swingbasics
 
Ingles 2do parcial
Ingles   2do parcialIngles   2do parcial
Ingles 2do parcial
 
Java GUI Programming for beginners-graphics.pdf
Java GUI Programming for beginners-graphics.pdfJava GUI Programming for beginners-graphics.pdf
Java GUI Programming for beginners-graphics.pdf
 
Session2-J2ME development-environment
Session2-J2ME development-environmentSession2-J2ME development-environment
Session2-J2ME development-environment
 
Md10 building java gu is
Md10 building java gu isMd10 building java gu is
Md10 building java gu is
 
UNIT-2-AJAVA.pdf
UNIT-2-AJAVA.pdfUNIT-2-AJAVA.pdf
UNIT-2-AJAVA.pdf
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
 
Working with the Calculator program Once imported run the.pdf
Working with the Calculator program Once imported  run the.pdfWorking with the Calculator program Once imported  run the.pdf
Working with the Calculator program Once imported run the.pdf
 
08graphics
08graphics08graphics
08graphics
 
User Guide of Regression Test & Validation Tool (v1.0)
User Guide of Regression Test & Validation Tool (v1.0)User Guide of Regression Test & Validation Tool (v1.0)
User Guide of Regression Test & Validation Tool (v1.0)
 
java swing
java swingjava swing
java swing
 

More from Riccardo Cardin

Java - Processing input and output
Java - Processing input and outputJava - Processing input and output
Java - Processing input and output
Riccardo Cardin
 
Java - Concurrent programming - Thread's advanced concepts
Java - Concurrent programming - Thread's advanced conceptsJava - Concurrent programming - Thread's advanced concepts
Java - Concurrent programming - Thread's advanced concepts
Riccardo Cardin
 
Design Pattern Comportamentali
Design Pattern ComportamentaliDesign Pattern Comportamentali
Design Pattern Comportamentali
Riccardo Cardin
 
Design Pattern Creazionali
Design Pattern CreazionaliDesign Pattern Creazionali
Design Pattern Creazionali
Riccardo Cardin
 
Diagrammi di Attività
Diagrammi di AttivitàDiagrammi di Attività
Diagrammi di Attività
Riccardo Cardin
 
Diagrammi Use Case
Diagrammi Use CaseDiagrammi Use Case
Diagrammi Use Case
Riccardo Cardin
 
Introduzione a UML
Introduzione a UMLIntroduzione a UML
Introduzione a UML
Riccardo Cardin
 
Mvc e di spring e angular js
Mvc e di   spring e angular jsMvc e di   spring e angular js
Mvc e di spring e angular js
Riccardo Cardin
 
Reactive programming principles
Reactive programming principlesReactive programming principles
Reactive programming principles
Riccardo Cardin
 

More from Riccardo Cardin (9)

Java - Processing input and output
Java - Processing input and outputJava - Processing input and output
Java - Processing input and output
 
Java - Concurrent programming - Thread's advanced concepts
Java - Concurrent programming - Thread's advanced conceptsJava - Concurrent programming - Thread's advanced concepts
Java - Concurrent programming - Thread's advanced concepts
 
Design Pattern Comportamentali
Design Pattern ComportamentaliDesign Pattern Comportamentali
Design Pattern Comportamentali
 
Design Pattern Creazionali
Design Pattern CreazionaliDesign Pattern Creazionali
Design Pattern Creazionali
 
Diagrammi di Attività
Diagrammi di AttivitàDiagrammi di Attività
Diagrammi di Attività
 
Diagrammi Use Case
Diagrammi Use CaseDiagrammi Use Case
Diagrammi Use Case
 
Introduzione a UML
Introduzione a UMLIntroduzione a UML
Introduzione a UML
 
Mvc e di spring e angular js
Mvc e di   spring e angular jsMvc e di   spring e angular js
Mvc e di spring e angular js
 
Reactive programming principles
Reactive programming principlesReactive programming principles
Reactive programming principles
 

Recently uploaded

BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 

Recently uploaded (20)

BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 

Java Graphics Programming

  • 1. GRAPHICS PROGRAMMING PROGRAMMAZIONE CONCORRENTE E DISTR. Università degli Studi di Padova Dipartimento di Matematica Corso di Laurea in Informatica, A.A. 2015 – 2016 rcardin@math.unipd.it
  • 2. Programmazione concorrente e distribuita SUMMARY  Introducing Swing  Main components  Layout management  Event handling 2Riccardo Cardin
  • 3. Programmazione concorrente e distribuita INTRODUCTION  A little bit of history  Java 1.0 refers to the Abstract Window Toolkit (AWT) for simple GUI programming  AWT delegates to the underlying OS the responsibility to create graphical components («peers»)  Look and feel of target platform  It was very hard to create high-quality portable GUIs  Java 1.2 intoduces Swing  Graphic components are painted onto blank windows  The only functionality required from the underlying windowing system is a way to put up windows and to paint onto them  Build on top of AWT 3Riccardo Cardin
  • 4. Programmazione concorrente e distribuita INTRODUCTION 4Riccardo Cardin
  • 5. Programmazione concorrente e distribuita INTRODUCTION  Swing features  A little bit slower than AWT  It’s not a real problem on modern machines  Rich and convenient set of user interface elements  Few dependencies on the underlying platform  Consistent user experience across platforms  Drawback: different look-and-feel from native GUIs  Many different look-and-feels (themes)  Metal, Ocean and Synth (JSE 5.0), Nimbus (JSE 7.0, vector drawings)  Package javax.swing: it is considered a Java ext. 5Riccardo Cardin
  • 6. Programmazione concorrente e distribuita INTRODUCTION  Swing Ocean look-and-feel 6Riccardo Cardin
  • 7. Programmazione concorrente e distribuita MAIN COMPONENTS  Frame  Top level window, Frame (AWT) or JFrame (Swing)  The only Swing component that is not painted on the canvas  Always use «J» components, which belong from Swing 7Riccardo Cardin EventQueue.invokeLater(new Runnable() { public void run() { SimpleFrame frame = new SimpleFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }); class SimpleFrame extends JFrame { private static final int DEFAULT_WIDTH = 300; private static final int DEFAULT_HEIGHT = 200; public SimpleFrame() { setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); } }
  • 8. Programmazione concorrente e distribuita MAIN COMPONENTS  Let me explain what’s going on in here...  By default a frame as size of 0 x 0 pixels, so SimpleFrame set the size of the frame in its ctor  You have to define what should happen when the user closes the application’s frame  JFrame.EXIT_ON_CLOSE: the program exit on close  Event dispatch thread  Finally, a frame has to be made visible, using setVisible(true) 8Riccardo Cardin EventQueue.invokeLater(new Runnable() { public void run() { // Configuration statement } }); You have to do ALWAYS in this way!!!
  • 9. Programmazione concorrente e distribuita MAIN COMPONENTS  Frame hierarchy  Component / Windows  Component is the base class of every GUI object  Resize and reshape actions  Frame properties  set / get methods  Toolkit class  Used to bind some components to a particular native toolkit impl.  Adapter pattern 9Riccardo Cardin Toolkit kit = Toolkit.getDefaultToolkit();
  • 10. Programmazione concorrente e distribuita MAIN COMPONENTS  Display information in a component  DO NOT DRAW DIRECTLY ONTO A FRAME!  A frame is considered a container for components  Use the content pane instead  Components are instances of JComponent / JPanel  Implement paintComponent method, that is called by the event handler every time a window needs to be redrawn 10Riccardo Cardin // Get the content pane and draw something on it Container contentPane = frame.getContentPane(); Component c = /* . . . */; contentPane.add(c); class MyComponent extends JComponent { public void paintComponent(Graphics g) { // code for drawing }}
  • 11. Programmazione concorrente e distribuita MAIN COMPONENTS 11Riccardo Cardin Used to organize the menu bar and content pane and to implement look-and-feel Used to add Components and to draw something onto the frame
  • 12. Programmazione concorrente e distribuita MAIN COMPONENTS 12Riccardo Cardin
  • 13. Programmazione concorrente e distribuita LAYOUT MANAGEMENT  JDK has not form designer tools  You need to write code to position (lay out) the UI components where you want them to be  Buttons, text fields, and other UI elements extend the class Component.  Components can be placed inside containers, such as panel.  Containers can themselves be put inside other containers  Container extends Component  Composite pattern 13Riccardo Cardin In general components are placed inside containers, and a layout manager determines the position and sizes of the components in the container
  • 14. Programmazione concorrente e distribuita LAYOUT MANAGEMENT 14Riccardo Cardin Container class stores references to itself
  • 15. Programmazione concorrente e distribuita LAYOUT MANAGEMENT 15Riccardo Cardin
  • 16. Programmazione concorrente e distribuita LAYOUT MANAGEMENT  Composite pattern  In Swing, the problem is that leaf components are subclasses of composite class 16Riccardo Cardin It is a composition of Component objects
  • 17. Programmazione concorrente e distribuita LAYOUT MANAGEMENT  Flowlayout  Elements are put in a row, sized at their preferred size  Default layout manager for a panel  If the horizontal space in the container is too small, the layout uses multiple rows.  Elements are centered horizontally by default  Layout changes accordingly to container size  Constructor permits to specify:  Left, right or center alignment  Vertical or horizontal gaps 17Riccardo Cardin Elements are put in rows
  • 18. Programmazione concorrente e distribuita LAYOUT MANAGEMENT  Add 3 buttons to a JPanel 18Riccardo Cardin public class BorderLayoutExample extends JFrame { public BorderLayoutExample(String title) { super(title); // Set the size of the window setSize(300, 200); // Add component to frame addComponentsToPane(getContentPane()); } private void addComponentsToPane(final Container pane) { // Panel with FlowLayout as default layout manager JPanel controls = new JPanel(); controls.add(new JButton("Button 1")); controls.add(new JButton("Button 2")); controls.add(new JButton("Button 3")); // Content pane of the frame, BorderLayout as default pane.add(controls, BorderLayout.SOUTH); }
  • 19. Programmazione concorrente e distribuita LAYOUT MANAGEMENT  BorderLayout  Defines 5 regions in which elements can be placed  Default layout manager of the JFrame content panel  BorderLayout.NORTH, BorderLayout.EAST...  Center is the default position  The edge components are laid first  When the container is resized, the dim. of the edge components are unchanged  It grows all components to fill the available space  Use an intermediate JPanel to contain the elements 19Riccardo Cardin
  • 20. Programmazione concorrente e distribuita LAYOUT MANAGEMENT  Build a window with 3 buttons at the bottom 20Riccardo Cardin public class BorderLayoutExample extends JFrame { public BorderLayoutExample(String title) { super(title); // Set the size of the window setSize(300, 200); // Add component to frame addComponentsToPane(getContentPane()); } private void addComponentsToPane(final Container pane) { // Panel with FlowLayout as default layout manager JPanel controls = new JPanel(); controls.add(new JButton("Button 1")); controls.add(new JButton("Button 2")); controls.add(new JButton("Button 3")); // Content pane of the frame, BorderLayout as default pane.add(controls, BorderLayout.SOUTH); }
  • 21. Programmazione concorrente e distribuita LAYOUT MANAGEMENT  GridLayout  Arranges all components in rows and columns like a spreadsheet  All components are given the same size (also in case of resizing of the window)  Usually used to model a small part of a UI, rather than the whole windows  Components are added starting from the first entry in the first row, then the second entry and so on 21Riccardo Cardin // Get the content pane and draw something on it // Valuing with a 0 the number of rows will allow the layout to // use as many rows as necessary panel.setLayout(new GridLayout(4, 4));
  • 22. Programmazione concorrente e distribuita LAYOUT MANAGEMENT  Build a windows with 4 buttons put in 2 rows 22Riccardo Cardin public class GridLayoutExample extends JFrame { public BorderLayoutExample(String title) { super(title); // Set the size of the window setSize(300, 200); // Add component to frame addComponentsToPane(getContentPane()); } private void addComponentsToPane(final Container pane) { // Set GridLayout to the panelb JPanel controls = new JPanel(); controls.setLayout(new GridLayout(2, 2)); controls.add(new JButton("Button 1")); controls.add(new JButton("Button 2")); controls.add(new JButton("Button 3")); controls.add(new JButton("Button 4")); pane.add(controls; }
  • 23. Programmazione concorrente e distribuita LAYOUT MANAGEMENT  CardLayout  Used to model two or more components that share the same display space  It is like playing card in a stack, where only the top card (component) is visible at any time  You can ask for either the first or the last card  You can ask to flip the deck backwards or forwards  You can specify a card with a specific name 23Riccardo Cardin
  • 24. Programmazione concorrente e distribuita LAYOUT MANAGEMENT  Build a window with two cards 24Riccardo Cardin public class CardLayoutExample extends JFrame { // ... private void addComponentsToPane(final Container pane) { // ... cards = new JPanel(new CardLayout()); cards.add(createCard1(), "Card 1"); cards.add(createCard2(), "Card 2"); } private JPanel createCombo() { // ... // Add combo a listener comboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { // Get the layout CardLayout layuot = (CardLayout) cards.getLayout(); layuot.show(cards, (String) e.getItem()); } }); We will introduce listeners in a moment
  • 25. Programmazione concorrente e distribuita LAYOUT MANAGEMENT 25Riccardo Cardin
  • 26. Programmazione concorrente e distribuita EVENT HANDLING  An operating environment constantly monitors events and reports them to the program  The program decides what to do in response to these events  Keystrokes, mouse clicks, and so on  In Java (AWT) the developer has the full control on how the events are transmitted from the event source to events listeners  Every object can be an event listener (delegation model)  Event listeners register themself to an event source  Obsever pattern  Events are objects of type java.util.EventObject 26Riccardo Cardin
  • 27. Programmazione concorrente e distribuita EVENT HANDLING  Summarizing  A listener object implements a listener interface  An event source can register listener and send them event objects  The event source sends events to every registered listener  The listener, using the event info, reacts accordingly 27Riccardo Cardin class MyListener implements ActionListener { public void actionPerformed(ActionEvent event) { // React to the event goes here } } JButton button = new Jbutton("OK"); button.addActionListener(listener); // Registering a listener
  • 28. Programmazione concorrente e distribuita EVENT HANDLING 28Riccardo Cardin An event source registers a listener Event source Event source notifies the listener The listener react accordingly
  • 29. Programmazione concorrente e distribuita EVENT HANDLING 29Riccardo Cardin
  • 30. Programmazione concorrente e distribuita EVENT HANDLING 30Riccardo Cardin
  • 31. Programmazione concorrente e distribuita EVENT HANDLING  Let’s see a simple example  First of all, let’s create the buttons  To create a button, simply create a JButton object, giving to it a label or an icon 31Riccardo Cardin We will show a panel populated with three buttons. When a button is clicked, we want the background color of the panel to change to a particular color. // Create the buttons JButton blueButton = new JButton("Yellow"); JButton blueButton = new JButton("Blue"); JButton redButton = new JButton("Red"); // Add them to a panel (flow layout anyone?) buttonPanel.add(yellowButton); buttonPanel.add(blueButton); buttonPanel.add(redButton);
  • 32. Programmazione concorrente e distribuita EVENT HANDLING  Let’s see a simple example  Then, let’s define button listeners 32Riccardo Cardin class ColorAction implements ActionListener { private Color backgroundColor; // The color to set to the panel public ColorAction(Color c) { backgroundColor = c; } public void actionPerformed(ActionEvent event) { // set panel background color } } // Create the listeners ColorAction yellowAction = new ColorAction(Color.YELLOW); ColorAction blueAction = new ColorAction(Color.BLUE); ColorAction redAction = new ColorAction(Color.RED); // Register listeners to buttons yellowButton.addActionListener(yellowAction); blueButton.addActionListener(blueAction); redButton.addActionListener(redAction);
  • 33. Programmazione concorrente e distribuita EVENT HANDLING  Let’s see a simple example  A problem rises: how can a listener modify a property of the panel?  Please, do not try to add listener’s func. to the frame  Violation of separation of concerns  Use inner classes instead! 33Riccardo Cardin class ButtonFrame extends JFrame { // The panel to change the color private JPanel buttonPanel; private class ColorAction implements ActionListener { private Color backgroundColor; public void actionPerformed(ActionEvent event) { // Changing the color to the main class panel buttonPanel.setBackground(backgroundColor); } } }
  • 34. Programmazione concorrente e distribuita EVENT HANDLING  Let’s see a simple example  Can we go even further?  Let’s use anonymous inner classes to handle events  The inner class mechanism automatically generates a constructor that stores all final variables that are used  Closure anyone?! 34Riccardo Cardin public void makeButton(String name, final Color backgroundColor) { JButton button = new JButton(name); buttonPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { buttonPanel.setBackground(backgroundColor); } }); }
  • 35. Programmazione concorrente e distribuita EVENT HANDLING 35Riccardo Cardin
  • 36. Programmazione concorrente e distribuita EVENT HANDLING  Let’s see a simple example  If the anonymous inner class method calls one method only, EventHandler class can be used  Reflection mechanism  The statement frame.loadData() is executed in response of an event  The statement frame.loadData(event.getSource.getText()) is executed 36Riccardo Cardin loadButton.addActionListener( EventHandler.create(ActionListener.class, frame, "loadData")); EventHandler.create(ActionListener.class, frame, "loadData", "source.text");
  • 37. Programmazione concorrente e distribuita EVENT HANDLING  Not all events are simply as button clicks  The listener WindowListener interface, that handles WindowEvent objects, has 7 methods  Probably you don’t need to defined them all!  Each AWT listener interfaces with more than one method comes with a companion Adapter  Implements all methods with "do nothing" operations 37Riccardo Cardin public interface WindowListener { void windowOpened(WindowEvent e); void windowClosing(WindowEvent e); void windowClosed(WindowEvent e); void windowIconified(WindowEvent e); void windowDeiconified(WindowEvent e); void windowActivated(WindowEvent e); void windowDeactivated(WindowEvent e); }
  • 38. Programmazione concorrente e distribuita EVENT HANDLING  Adapter pattern  Class adapter  Object adapter 38Riccardo Cardin Target interface Source interface Adapt source interface to target
  • 39. Programmazione concorrente e distribuita EVENT HANDLING  What if you need to share the same behaviour in response to more than one event?  Use Action interface, that extends ActionListener  It encapsulates the description of the «command» and parameters that are necessary to carry out the command  Command pattern  AbstractAction is an adapter class provided by the JDK  Then simply add the action to your UI components using constructor 39Riccardo Cardin void actionPerformed(ActionEvent event) // Add a property to the action object indexed by key void putValue(String key, Object value) // Get a property indexed by key Object getValue(String key) new JButton(new MyAction());
  • 40. Programmazione concorrente e distribuita EVENT HANDLING Interface Method Params Generated by ActionListener actionPerformed ActionEvent • getActionCommand • getModifiers ActionButton JComboBox JTextField Timer AdjustmentListener adjustementValueChang ed AdjustementEvent • getAdjustable • getAdjustableType • getValue JScrollbar ItemListener itemStateChanged ItemEvent • getItem • getItemSelectable • getStateChange AbstractButton JComboBox FocusListener focusGained focusLost FocusEvent • isTemporary Component KeyListener keyPressed keyReleased keyTyped KeyEvent • getKeyChar • getKeyCode • getKeyModifiersText • getKeyText • isActionKey Component 40Riccardo Cardin
  • 41. Programmazione concorrente e distribuita EVENT HANDLING ...and so on 41Riccardo Cardin Interface Method Params Generated by MouseListener mousePressed mouseReleased mouseEntered mouseExited mouseClicked MouseEvent • getClickCount • getX • getY • getPoint • translatePoint Component MouseMotionListener mouseDragged mouseMoved MouseEvent Component MouseWheelListener mouseWheelMoved MouseWheelEvent • getWheelRotation • getScrollAmount Component WindowListener windowClosing windowOpened windowIconified windowDeiconified windowClosed windowActivated windowDeactivated WindowEvent • getWindow Window
  • 42. Programmazione concorrente e distribuita CONCLUSIONS 42Riccardo Cardin
  • 43. Programmazione concorrente e distribuita EXAMPLES 43Riccardo Cardin https://github.com/rcardin/pcd-snippets
  • 44. Programmazione concorrente e distribuita REFERENCES  Chap. 7 «Graphics Programming», Core Java Volume I - Fundamentals, Cay Horstmann, Gary Cornell, 2012, Prentice Hall  Chap. 8 «Event Handling», Core Java Volume I - Fundamentals, Cay Horstmann, Gary Cornell, 2012, Prentice Hall  Chap. 9 «User Interface Components with Swing», Core Java Volume I - Fundamentals, Cay Horstmann, Gary Cornell, 2012, Prentice Hall  How to Use FlowLayout https://docs.oracle.com/javase/tutorial/uiswing/layout/flow.html  How to Use CardLayout https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html  How to Use Actions https://docs.oracle.com/javase/tutorial/uiswing/misc/action.html 44Riccardo Cardin