This presentation introduces the main features of Swing, an UI development library for the Java ecosystem. The main focus of the slides is to show the basic features of Swing, such as:
- Main components (JFrame, JPanel, ...)
- Layout management (FlowLayout, BorderLayout, GridLayout, ...)
- Event handling
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about the five SOLID principles of Object Oriented Design described by Rober C. Martin in his best-seller book "Agile Principles, Patterns, and Practices in C#". The five principle described are:
- Single Responsibility Principle
- Open-Close Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about the five SOLID principles of Object Oriented Design described by Rober C. Martin in his best-seller book "Agile Principles, Patterns, and Practices in C#". The five principle described are:
- Single Responsibility Principle
- Open-Close Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
Report contains digital and analog design flow procedures in detail, working, Simulation and Synthesize mapped output. Full custom Schematic and layout design by using virtuoso encounter cadence tool.
Placement Papers are published here to help freshers to get themselves prepared for the tests and successfully procure jobs in top companies of India including Infosys, Wipro, TCS, HCL, HP, Accenture, CTS etc. This is the section where you can find previous and latest questions, practice them with the solutions in hand.
SIMWARE SimDeveloper provides a Visual Modeling Environment based on Simulink to focuse your engineering resources in the most important thing: modeling. Not coding. Say bye to unfinishable debugging and complex C++ code. This is an easy-to-use tool complimentary to the SIMWARE Framework and based on the Model Driven Architecture (MDA) paradigm. Just what your Program Manager will like.
SIMWARE, despite of being a new player in the so competitive Training & Simulation market, has been field-tested by prestigious organizations worldwide like the Spanish Armed Forces, INDRA, NAVANTIA, National Institute of Space Research in Brazil among others. It has been successfully implemented in different simulation systems, connecting legacy simulators and third-party COTS like VBS2, VR-Forces, StealBeastPro or STAGE.
Design functional solutions in Java, a practical exampleMarian Wamsiedel
Starting with a simple programming task I present here some solutions based on functional programming and a standard object oriented one.
The code samples are written in Java. A github repository contains the complete code implementation.
This presentation talks about some commonly used software architecture patterns. The main features of the following architectural patterns are described:
- Layered architecture
- Event-driven architecture (both mediator and broker topology)
- Microservices architecture (API-REST based, REST based, Centralized message topology)
Each pattern is analyzed in terms of:
- Overall agility
- Ease of deployment
- Testability
- Performance
- Scalability
- Ease of develpment.
The slide refers to the online book "Software Architecture Patterns", Mark Richards, 2015, O’Reilly.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about dependecy injection, an architectural design pattern that aims to help developer to resolve dependencies between objects. Starting by describing general problem of dependecy resolution, the presentation continues presenting Inversion of Control (IoC) pattern, constructor injection and setting injection. As examples, some frameworks and libraries are reported, such as:
- Google Guice
- Spring framework
- AngularJS
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
Report contains digital and analog design flow procedures in detail, working, Simulation and Synthesize mapped output. Full custom Schematic and layout design by using virtuoso encounter cadence tool.
Placement Papers are published here to help freshers to get themselves prepared for the tests and successfully procure jobs in top companies of India including Infosys, Wipro, TCS, HCL, HP, Accenture, CTS etc. This is the section where you can find previous and latest questions, practice them with the solutions in hand.
SIMWARE SimDeveloper provides a Visual Modeling Environment based on Simulink to focuse your engineering resources in the most important thing: modeling. Not coding. Say bye to unfinishable debugging and complex C++ code. This is an easy-to-use tool complimentary to the SIMWARE Framework and based on the Model Driven Architecture (MDA) paradigm. Just what your Program Manager will like.
SIMWARE, despite of being a new player in the so competitive Training & Simulation market, has been field-tested by prestigious organizations worldwide like the Spanish Armed Forces, INDRA, NAVANTIA, National Institute of Space Research in Brazil among others. It has been successfully implemented in different simulation systems, connecting legacy simulators and third-party COTS like VBS2, VR-Forces, StealBeastPro or STAGE.
Design functional solutions in Java, a practical exampleMarian Wamsiedel
Starting with a simple programming task I present here some solutions based on functional programming and a standard object oriented one.
The code samples are written in Java. A github repository contains the complete code implementation.
This presentation talks about some commonly used software architecture patterns. The main features of the following architectural patterns are described:
- Layered architecture
- Event-driven architecture (both mediator and broker topology)
- Microservices architecture (API-REST based, REST based, Centralized message topology)
Each pattern is analyzed in terms of:
- Overall agility
- Ease of deployment
- Testability
- Performance
- Scalability
- Ease of develpment.
The slide refers to the online book "Software Architecture Patterns", Mark Richards, 2015, O’Reilly.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about dependecy injection, an architectural design pattern that aims to help developer to resolve dependencies between objects. Starting by describing general problem of dependecy resolution, the presentation continues presenting Inversion of Control (IoC) pattern, constructor injection and setting injection. As examples, some frameworks and libraries are reported, such as:
- Google Guice
- Spring framework
- AngularJS
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces some advanced concepts of generics in Java. These slides introduce the following concepts:
- Generic classes and methods
- Type variable bounds
- Type erasure process
- Generics and inheritance
- Wildcard types
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces some concepts about the Java Collection framework. These slides introduce the following concepts:
- Collections and iterators
- Linked list and array list
- Hash set and tree set
- Maps
- The collection framework
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces basic concepts about the Java socket abstraction. These slides introduce the following concepts:
- What is a socket
- How to implement a client program
- How to implement a server program
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
Errori comuni nei documenti di Analisi dei RequisitiRiccardo Cardin
This presentation talks about common errors that I found in my career in documents of specification of requirements. In the presentation are described common errors on use cases, use cases' diagrams and on requirements' specification.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about the main features of UML class diagrams. The slides contain information about how to represent a class, what is a classe feature, what are possible association types, class dependency, hineritance and subtyping.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces the concept of design pattern in object oriented programming and design. The slides contain information about what a design pattern is, why should we use design pattern and how design patterns could be grouped togheter. The ideas presented in the slides are taken directly from GoF's book "Design Patterns".
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces the Java concept of thread. It is the first part of a series of slides dedicated to concurrent programming. This slides introduces some basics concepts, such as:
- Differences between processes and threads
- Thread's basics
- Thread's states
- Introduction to UML sequence diagrams
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about the main features of UML class diagrams. The slides contain information about how to use sequence diagrams to represent components' interactions in a software system. UML 2.x featuers are also described, like frames.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about structural design patterns. In software engineering, structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities. In particular in the slides are described the following patterns:
- Decorator
- Proxy
- Facade
- Adapter
Design patterns are presented using examples in Java, Scala and Javascript.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation is based on Joakim\’s experiences from moving from Java to Scala http://www.scala-lang.org/node/960#Joak We will explore how to move from Java to Scala and why. We\’ll look at things that you will run into sooner rather than later such as Scala\’s collection APIs, Options and higher order functions and special syntax. You will leave this presentation with good foundation to use Scala in practice; perhaps even in your current Java project and ideally with an appetite to learn more.
This presentation introduces basic concepts about the Java Remote Method Invocation, a.k.a. RMI. These slides introduce the following concepts:
- Remote interfaces
- Dynamic code loading
- Serialization
- Security manager
- Exporting remote objects
- Compiling and running RMI programs
- Distributed garbage collection
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces the concept of synchronization beatween threads, as implemented in the Java platform. It is the first part of a series of slides dedicated to thread synchronization. This slides introduces the following concepts:
- Thread safety
- Types of race conditions
- Locking (reentrant locks, intrinsic locks, synchronized blocks)
- Locking pitfalls
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces the concept of synchronization beatween threads, as implemented in the Java platform. It is the second part of a series of slides dedicated to thread synchronization. This slides introduces the following concepts:
- Conditional locking
- Volatile variables
- Thread confinement
- Immutability
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces the main features of Scala, an object oriented and functional programming language. The main focus of the slides is to show how the language implements natively some of the patterns and best practices that are no present in other programming languages, such as Java, C++ and so on.
In detail, the presentation spans these concepts:
- Language's main syntax
- Classes, abstract classes, objects and traits (mixin)
- The Option class
- An introduction to generics
- Implicit classes
- Functions
- Recursion (simple and tail)
- Currying
- Call by value / name
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
Design pattern architetturali Model View Controller, MVP e MVVMRiccardo Cardin
This presentation talks about model view controller, model view presenter and model view viewmodel patterns. These are architectural design patterns for implementing user interfaces. They divide a given software application into three interconnected parts, so as to separate internal representations of information from the ways that information is presented to or accepted from the user. Also, they promote separation of concerns. As examples, some frameworks are reported, such as:
- Spring MVC
- BackboneJS
- AngularJS
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
Java Exception Handling, Assertions and LoggingRiccardo Cardin
This presentation introduces the java exception handling mechanisms. In detail, the main focus of the slides is to show how the language implements its exception handling polices, such as:
- Checked and uncheked exception
- Try / catch blocks
- Assertions
- Logging
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
Working with the Calculator program Once imported run the.pdficonsystemsslm
Working with the Calculator program.
Once imported run the application (CalcMain is the driver)
Determine what Calculator does and how it works investigate.
Add multiplication and subtraction buttons to the application.
Test to make sure all functionality works as you expect.
Export updated Calculator to a Runnable JAR file.
Go to the location where you put the runnable JAR and double click it to run the application
Capture the runnable JAR file runtime screen shot.
CalcMain.java
import javax.swing.JFrame;
public class CalcMain {
public static void main(String [] args)
{
JFrame frame = new JFrame("Calculator");
//2. Optional: What happens when the frame closes?
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//3. Create your panel and put it in the frame.
frame.getContentPane().add(new Calculator());
//4. Size the frame.
frame.setSize(300, 550);
//5. Show it.
frame.setVisible(true);
}
}
Calculator.java
import javax.swing.*;
import java.awt.Color;
import java.awt.event.*;
public class Calculator extends JPanel implements ActionListener {
String num1="";
String num2="";
String operator="";
boolean usingFirst=true;
double total=0;
JTextField display;
JButton b1;
JButton b2;
JButton b3;
JButton b4;
JButton b5;
JButton b6;
JButton b7;
JButton b8;
JButton b9;
JButton b0;
JButton bdec;
JButton bclear;
JButton bequals;
JButton bplus;
JButton bmult;
JButton bsub;
public Calculator()
{
this.setBackground(Color.white);
setLayout(null);
display=new JTextField();
b1=new JButton("1");
b2=new JButton("2");
b3=new JButton("3");
b4=new JButton("4");
b5=new JButton("5");
b6=new JButton("6");
b7=new JButton("7");
b8=new JButton("8");
b9=new JButton("9");
b0=new JButton("0");
bdec=new JButton(".");
bclear=new JButton("C");
bequals = new JButton( "=");
bplus=new JButton("+");
bmult=new JButton("*");
bsub=new JButton("-");
display.setBounds(0,0,205,50);
b1.setBounds(0,200,50,50);
b2.setBounds(50,200,50,50);
b3.setBounds(100,200,50,50);
bplus.setBounds(154,200,50,50);
b4.setBounds(0,150,50,50);
b5.setBounds(50,150,50,50);
b6.setBounds(100,150,50,50);
bmult.setBounds(154,150,50,50);
b7.setBounds(0,100,50,50);
b8.setBounds(50,100,50,50);
b9.setBounds(100,100,50,50);
bsub.setBounds(154,100,50,50);
b0.setBounds(0,250,50,50);
bdec.setBounds(50,250,50,50);
bclear.setBounds(100,250,50,50);
bequals.setBounds(154,250,50,50);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
add(b9);
add(b0);
add(bdec);
add(display);
add(bclear);
add(bequals);
add(bplus);
add(bmult);
add(bsub);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b0.addActionListener(this);
bequals.addActionListener(this);
bplus.addActionListener(this);
bclear.addActionListener(this);
bdec.addActionListener(this);
bmult.addActionListener(this);
bsub.addActionListener(this);
}
public vo.
This presentation introduces basic concepts about the Java I/O framework based on input and output streams. These slides introduce the following concepts:
- Obtaining streams
- Reading / writing bytes
- Character encodings
- Text input / output
- Random access files
- Processing files
- URLs
- Serialization
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces some advanced concepts of threads, as implemented in the Java platform. It is part of a series of slides dedicated to threads. This slides introduces the following concepts:
- Callable
- Futures
- Executors and executor services
- Deadlocks (brief introduction)
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about behavioural design patterns. In software engineering, behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication. In particular in the slides are described the following patterns:
- Command
- Iterator
- Observer
- Strategy
- Template Method
Design patterns are presented using examples in Java, Scala and Javascript.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about creational design patterns. In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. In particular in the slides are described the following patterns:
- Singleton
- Builder
- Abstract Factory
Design patterns are presented using examples in Java, Scala and Javascript.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about the main features of UML activity diagrams. The slides contain information about which are the main components of activity diagrams, how to use them to represent business processes and software algorithms.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about the main features of UML use cases and use cases diagrams. The slides contain information about what is a scenario, an actor, an use case and interactions between them.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
A brief introduction to UML: the history, what are the problems that UML tries to resolve and how we should use it during software design and development.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
A very introductive presentation about how Model-View-Controller pattern (MVC) and Dependence Injection (DI) are implemented in some popular frameworks, such as Spring and Angular JS.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
A very introductive presentation about reactive programming principles. Starting from synchronous standard programming, I try to present the needs that driven to reactive programming. Callbacks, Future, Promises, Observables and Actor model are the main issues. I also make an introduction to the Reactive Manifesto.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus
As part of the DOE Integrated Research Infrastructure (IRI) program, NERSC at Lawrence Berkeley National Lab and ALCF at Argonne National Lab are working closely with General Atomics on accelerating the computing requirements of the DIII-D experiment. As part of the work the team is investigating ways to speedup the time to solution for many different parts of the DIII-D workflow including how they run jobs on HPC systems. One of these routes is looking at Globus Compute as a way to replace the current method for managing tasks and we describe a brief proof of concept showing how Globus Compute could help to schedule jobs and be a tool to connect compute at different facilities.
GraphSummit Paris - The art of the possible with Graph TechnologyNeo4j
Sudhir Hasbe, Chief Product Officer, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
May Marketo Masterclass, London MUG May 22 2024.pdfAdele Miller
Can't make Adobe Summit in Vegas? No sweat because the EMEA Marketo Engage Champions are coming to London to share their Summit sessions, insights and more!
This is a MUG with a twist you don't want to miss.
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
JASMIN is the UK’s high-performance data analysis platform for environmental science, operated by STFC on behalf of the UK Natural Environment Research Council (NERC). In addition to its role in hosting the CEDA Archive (NERC’s long-term repository for climate, atmospheric science & Earth observation data in the UK), JASMIN provides a collaborative platform to a community of around 2,000 scientists in the UK and beyond, providing nearly 400 environmental science projects with working space, compute resources and tools to facilitate their work. High-performance data transfer into and out of JASMIN has always been a key feature, with many scientists bringing model outputs from supercomputers elsewhere in the UK, to analyse against observational or other model data in the CEDA Archive. A growing number of JASMIN users are now realising the benefits of using the Globus service to provide reliable and efficient data movement and other tasks in this and other contexts. Further use cases involve long-distance (intercontinental) transfers to and from JASMIN, and collecting results from a mobile atmospheric radar system, pushing data to JASMIN via a lightweight Globus deployment. We provide details of how Globus fits into our current infrastructure, our experience of the recent migration to GCSv5.4, and of our interest in developing use of the wider ecosystem of Globus services for the benefit of our user community.
Quarkus Hidden and Forbidden ExtensionsMax Andersen
Quarkus has a vast extension ecosystem and is known for its subsonic and subatomic feature set. Some of these features are not as well known, and some extensions are less talked about, but that does not make them less interesting - quite the opposite.
Come join this talk to see some tips and tricks for using Quarkus and some of the lesser known features, extensions and development techniques.
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaYara Milbes
Discover the transformative power of the WhatsApp API in our latest SlideShare presentation, "Top 7 Unique WhatsApp API Benefits." In today's fast-paced digital era, effective communication is crucial for both personal and professional success. Whether you're a small business looking to enhance customer interactions or an individual seeking seamless communication with loved ones, the WhatsApp API offers robust capabilities that can significantly elevate your experience.
In this presentation, we delve into the top 7 distinctive benefits of the WhatsApp API, provided by the leading WhatsApp API service provider in Saudi Arabia. Learn how to streamline customer support, automate notifications, leverage rich media messaging, run scalable marketing campaigns, integrate secure payments, synchronize with CRM systems, and ensure enhanced security and privacy.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Atelier - Innover avec l’IA Générative et les graphes de connaissancesNeo4j
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Allez au-delà du battage médiatique autour de l’IA et découvrez des techniques pratiques pour utiliser l’IA de manière responsable à travers les données de votre organisation. Explorez comment utiliser les graphes de connaissances pour augmenter la précision, la transparence et la capacité d’explication dans les systèmes d’IA générative. Vous partirez avec une expérience pratique combinant les relations entre les données et les LLM pour apporter du contexte spécifique à votre domaine et améliorer votre raisonnement.
Amenez votre ordinateur portable et nous vous guiderons sur la mise en place de votre propre pile d’IA générative, en vous fournissant des exemples pratiques et codés pour démarrer en quelques minutes.
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Globus
The U.S. Geological Survey (USGS) has made substantial investments in meeting evolving scientific, technical, and policy driven demands on storing, managing, and delivering data. As these demands continue to grow in complexity and scale, the USGS must continue to explore innovative solutions to improve its management, curation, sharing, delivering, and preservation approaches for large-scale research data. Supporting these needs, the USGS has partnered with the University of Chicago-Globus to research and develop advanced repository components and workflows leveraging its current investment in Globus. The primary outcome of this partnership includes the development of a prototype enterprise repository, driven by USGS Data Release requirements, through exploration and implementation of the entire suite of the Globus platform offerings, including Globus Flow, Globus Auth, Globus Transfer, and Globus Search. This presentation will provide insights into this research partnership, introduce the unique requirements and challenges being addressed and provide relevant project progress.
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
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
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
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
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
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
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);
}
});
}
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());
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