Lecture 14 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
Lecture 13 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
Java Course 12: XML & XSL, Web & ServletsAnton Keks
Lecture 12 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
Java Course 7: Text processing, Charsets & EncodingsAnton Keks
Lecture 7 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
Do you know the difference between charset & encoding? Every programmer nowadays MUST understand these terms, how they work, and how to use them. Otherwise we constantly face broken software refusing to work with international characters properly.
Lecture 15 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
Gives an overview of more advanced Java topics.
Java is a general-purpose, object-oriented computer programming language that offers special features that allow programs to take advantage of the power and flexibility of the Internet.
Lecture 13 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
Java Course 12: XML & XSL, Web & ServletsAnton Keks
Lecture 12 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
Java Course 7: Text processing, Charsets & EncodingsAnton Keks
Lecture 7 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
Do you know the difference between charset & encoding? Every programmer nowadays MUST understand these terms, how they work, and how to use them. Otherwise we constantly face broken software refusing to work with international characters properly.
Lecture 15 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
Gives an overview of more advanced Java topics.
Java is a general-purpose, object-oriented computer programming language that offers special features that allow programs to take advantage of the power and flexibility of the Internet.
Lecture 6 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
Gives an overview how a software developer should organize their daily work, apart from technical skills.
Introduces Agile software development practices from XP and Scrum.
Core Java introduction | Basics | free course Kernel Training
http://kerneltraining.com/core-java/
Learn the basics of Java and gain practical experience that is required to begin your career in java programming. Kernel Training has designed classroom and online course to upgrade your knowledge and skills in core Java.
Course Curriculum:
Introduction to Java
JDK and practical applications
Java Basic Data Types and Operators
Programming Constructs, Classes and Methods, constructor and Finalizer
Polymorphism
Inheritance
Method overriding and abstract classes
Packages and Interfaces
Strings and Arrays
Enums
Core Java Tutorial. In case you want to get trained in Spring Framework you can refer here:
<a href="https://www.emexotechnologies.com/courses/java-development-training/core-java-training/">Java Training</a>
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Sagar Verma
16. Threads in Java
Non-Threaded Applications
Threaded Applications
Process based multitasking Vs Thread based multitasking
Thread API in Java
Creating Threads
States of a Thread
Synchronization for threads; static and non-static synchronized methods; blocks; concept of object and class locks
Coordination between threads - wait, notify and notifyAll methods for inter-thread communication
17. Applets
What are applets?
Need for Applets
Different ways of running an applet program
Applet API hierarchy
Life Cycle of an applet
Even Handlers for applets, mouse events, click events
18. Swing GUI
Introduction to AWT
Introduction to Swing GUI
Advantages of Swing over AWT
Swing API
Swing GUI Components
Event Handlers for Swing
Sample Calculator application using Swing GUI and Swing Event handling
19. JDBC
What is JDBC; introduction
JDBC features
JDBC Drivers
Setting up a database and creating a schema
Writing JDBC code to connect to DB
CRUD Operations with JDBC
Statement types in JDBC
Types of Rowset, ResultSet in JDBC
20. Access Modifiers in Java
What are access modifiers?
Default
Protected
Private
Public
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...Jorge Hidalgo
Slides from JavaOne 2014 conference session CON2013
The Java compiler and annotation processors are powerful tools within the Java platform, and both, combined, unleash great power in developers’ hands, as this session illustrates. Triggered during the Java compilation process, APs can be used to generate new sources and configuration from metadata present in the class source. Why expend time creating a BeanInfo class or dealing with boring XML configuration files when you can have them easily created at compilation time? Moreover, APs are compatible with IDEs and build tools, and hence they are virtually everywhere your Java code is. Unleash the power of annotation processors, and let them do the hard work for you
Lecture 6 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
Gives an overview how a software developer should organize their daily work, apart from technical skills.
Introduces Agile software development practices from XP and Scrum.
Core Java introduction | Basics | free course Kernel Training
http://kerneltraining.com/core-java/
Learn the basics of Java and gain practical experience that is required to begin your career in java programming. Kernel Training has designed classroom and online course to upgrade your knowledge and skills in core Java.
Course Curriculum:
Introduction to Java
JDK and practical applications
Java Basic Data Types and Operators
Programming Constructs, Classes and Methods, constructor and Finalizer
Polymorphism
Inheritance
Method overriding and abstract classes
Packages and Interfaces
Strings and Arrays
Enums
Core Java Tutorial. In case you want to get trained in Spring Framework you can refer here:
<a href="https://www.emexotechnologies.com/courses/java-development-training/core-java-training/">Java Training</a>
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Sagar Verma
16. Threads in Java
Non-Threaded Applications
Threaded Applications
Process based multitasking Vs Thread based multitasking
Thread API in Java
Creating Threads
States of a Thread
Synchronization for threads; static and non-static synchronized methods; blocks; concept of object and class locks
Coordination between threads - wait, notify and notifyAll methods for inter-thread communication
17. Applets
What are applets?
Need for Applets
Different ways of running an applet program
Applet API hierarchy
Life Cycle of an applet
Even Handlers for applets, mouse events, click events
18. Swing GUI
Introduction to AWT
Introduction to Swing GUI
Advantages of Swing over AWT
Swing API
Swing GUI Components
Event Handlers for Swing
Sample Calculator application using Swing GUI and Swing Event handling
19. JDBC
What is JDBC; introduction
JDBC features
JDBC Drivers
Setting up a database and creating a schema
Writing JDBC code to connect to DB
CRUD Operations with JDBC
Statement types in JDBC
Types of Rowset, ResultSet in JDBC
20. Access Modifiers in Java
What are access modifiers?
Default
Protected
Private
Public
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...Jorge Hidalgo
Slides from JavaOne 2014 conference session CON2013
The Java compiler and annotation processors are powerful tools within the Java platform, and both, combined, unleash great power in developers’ hands, as this session illustrates. Triggered during the Java compilation process, APs can be used to generate new sources and configuration from metadata present in the class source. Why expend time creating a BeanInfo class or dealing with boring XML configuration files when you can have them easily created at compilation time? Moreover, APs are compatible with IDEs and build tools, and hence they are virtually everywhere your Java code is. Unleash the power of annotation processors, and let them do the hard work for you
Introduction to java beans, java beans, Core java, j2se, getting started with java beans programming, java to standard edition, beans in java, beans programming in java
A bean is a reusable software component based on Sun's JavaBeans specification that can be manipulated visually in a builder tool.“
The JavaBeans technology enables vendors to create environments that make it dramatically easier to develop user interfaces for Java applications.
Lecture 11 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
Describes goods and bads of software architecture as well as common design patterns.
01. Introduction to programming with javaIntro C# Book
In this chapter we will take a look at the basic programming terminology and we will write our first Java program. We will familiarize ourselves with programming – what it means and its connection to computers and programming languages.
This is the material for Tampere workshop on 14th May 2018.
How to combine modern technologies such as Java 10, Spring Boot 2, Docker, to create more lightweight and modern microservices - or any services you like.
Applet Returns: The new generation of Java Plug-insSerge Rehem
This article will reveal the most important changes in the Java Plug-in architecture since JDK1.6update10, showing practical examples why we believe Applets are definitively back.
Still running on Java 8? Tempted by new versions of Java, but afraid too? This material contains some information on what to expect, and what kind of lessons were learned taking multitude of Java 8 projects to Java 9, 10, and 11.
What is Java Technology (An introduction with comparision of .net coding)Shaharyar khan
A introductory slides for those who want to learn and know some basics of Java.Also for those persons who want to compare coding difference between Java and .net
Similar to Java Course 14: Beans, Applets, GUI (20)
Lecture 10 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
Lecture 3 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
Discusses more Java basics and Object Oriented Programming.
Interactive technical talk for the Agile Saturday VI.
Accompanied with live coding. All code is available on github: https://github.com/angryziber/patterns
Talk from Agile Saturday 3 event in Estonia.
It is about being professional in general as well as following agile best practices, such as build automation and continuous integration.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
2. Java Beans
● JavaBeans is a component technology (like CORBA, ActiveX, etc)
– JavaBeans API allows creation of reusable, self-contained, cross-
platform components.
– Java components are called “beans”
– Beans can be used in Applets, applications, or other Beans.
– Beans are usually UI components, but it is not a requirement
●
There are many JavaBeans-compatible visual tools
● Formerly, there was the BDK (Bean Development Kit), which
contained BeanBox. Now it is superseded by BeanBuilder.
● Nowadays, the concept of “beans” is used also outside of JavaBeans
(not using java.beans API), e.g. in many server-side frameworks.
Sometimes these beans are called POJOs (Plain Old Java Objects)
Java course – IAG0040 Lecture 14
Anton Keks Slide 2
3. Bean basics
● Beans can expose their
– properties, which can be modified at design time
– actions (methods to do something)
– events
● java.beans.Introspector analyses Java Bean classes
– Generally automatically using Reflection API
– Or using the provided BeanInfo implementation (optional)
●
it must be named XyzBeanInfo for bean named Xyz
● Introspector.getBeanInfo(Xyz.class) will return a
BeanInfo instance, describing the Xyz bean
Java course – IAG0040 Lecture 14
Anton Keks Slide 3
4. How to make a Bean?
● A Java bean is a Java class that
– follows certain rules (conventions, design patterns), which
enable dynamic discovery of its features
– is Serializable (not strictly enforced)
– has a default constructor (parameter-less)
– can extend any class (no restrictions), but usually they extend
some GUI container classes
– has properties defined by corresponding getters and setters
(getXxx(), isXxx() and setXxx() public methods, where xxx is the
property name)
– has public void action methods
● methods can throw any exceptions
Java course – IAG0040 Lecture 14
Anton Keks Slide 4
5. More features
●
Bean properties can have PropertyEditors assigned
●
More complex editing is possible using the Customizer
interface (it can customize the whole bean at once)
● Aside from properties, Beans can have events
– event listeners must implement an interface (e.g.
ActionListener)
– Bean must provide two methods: addXXX() and removeXXX()
● addActionListener(ActionListener listener)
● removeActionListener(ActionListener listener)
– The interface must define a method, taking the event object
● actionPerformed(ActionEvent e)
Java course – IAG0040 Lecture 14
Anton Keks Slide 5
6. Persistence
●
Every bean is Serializable, hence can be easily
serialized/deserialized
– using ObjectOutputStream and ObjectInputStream
●
Long-term bean-specific serialization to XML is
also possible
– using XMLEncoder and XMLDecoder
– these enforce Java bean convention very strictly
– smart enough to persist only required (restorable)
properties, i.e. read-write properties with non-
default values
Java course – IAG0040 Lecture 14
Anton Keks Slide 6
7. Warning: Java Beans ≠ EJB
●
EJB are Enterprise Java Beans
● EJB are part of Java EE (Enterprise Edition)
● EJB and JavaBeans have very few in common
● EJB = bad thing (heavy-weight)
– at least before EJB 3.0
– even EJB architects at Sun agree on that now
●
Don't confuse yourself
Java course – IAG0040 Lecture 14
Anton Keks Slide 7
8. Bean task
1. Write a simple CommentBean
with String property comment
2. Try using the Introspector on it
3. Make it a GUI bean by extending java.awt.Canvas
4. Make it display text: override the paint() method, use
g.drawString()
5. Make the comment text scroll from right to left by using a Timer or
a manually written Thread
6. Tip: run it temporarily with this code in the main() method
Frame frame = new Frame(); frame.add(new CommentBean());
frame.setSize(w, h); frame.setVisible(true);
Java course – IAG0040 Lecture 14
Anton Keks Slide 8
9. Java GUI toolkits
●
Most Java GUI toolkits are cross-platform, as Java itself
●
The most popular ones are
– AWT (Abstract Widgets Toolkit), java.awt – the first GUI toolkit for
Java, the most basic one, sometimes may look ugly.
● The principle of LCD (least common denominator)
– JFC Swing, javax.swing – pure Java, supports pluggable look-and-
feels, more widgets, more powerful.
●
Included in JRE distribution
– SWT (Standard Widget Toolkit), org.eclipse.swt – developed for
Eclipse, can be used stand-alone.
● Provides native look-and-feel on every platform.
● Implemented as thin layer on native libraries for many platforms
Java course – IAG0040 Lecture 14
Anton Keks Slide 9
10. Java 1.6 desktop additions
● Cross-platform system tray support
– SystemTray.getSystemTray();
– tray.add(new TrayIcon(img, “Hello”));
●
Cross-platform java.awt.Desktop API
– Desktop.getDesktop();
– desktop.browse() - opens a web browser
– desktop.mail() - opens a mail client
– open(), edit(), print() - for arbitrary documents
– all this uses file/URL associations in the OS
● These may not be supported on each platform
– use isSupported() methods to check
Java course – IAG0040 Lecture 14
Anton Keks Slide 10
11. Java Applets
● Applets were the killer-app for Java
● In short, Applets are GUI Java applications, embedded in HTML
pages, and distributed over the Internet
●
Convenient to deploy centrally, convenient to run
●
Built-in security
●
Nowadays not as popular, because of Servlets, AJAX, Flash,
and aggressiveness of Microsoft (Java is no longer shipped with
Windows by default)
●
Applets are created by extending one of these classes:
– java.applet.Applet – older, AWT-based API
– javax.swing.JApplet – newer, Swing-based API (extends Applet itself)
Java course – IAG0040 Lecture 14
Anton Keks Slide 11
12. Applet API
● The applet API lets you take advantage of the close relationship
that applets have with Web browsers. See both Applet and
AppletContext (obtainable with getAppletContext())
● Applets can use these APIs to do the following:
– Be notified by the browser of state changes: start(), stop(), destroy()
– Load data files specified relative to the URL of the applet or the page in
which it is running: getCodeBase(), getDocumentBase(), getImage()
– Display short status strings: showStatus()
– Make the browser display a document: showDocument()
– Find other applets running in the same page: getApplets()
– Play sounds: getAudioClip(), play()
– Get parameters specified by the user in the <APPLET> tag:
getParameter(), getParameterInfo()
Java course – IAG0040 Lecture 14
Anton Keks Slide 12
13. Applets and Security
● The goal is to make browser users feel safe
● SecurityManager is checking for security violations
● SecurityException (unchecked) is thrown if something is not allowed
● In general, the following is forbidden:
– no reading/writing files on local host
– network connections only to the originating host
– no starting of programs, no loading of libraries
– all separate applet windows are identified with a warning message
– some system properties are hidden
●
Trusted Applets can be allowed to do otherwise forbidden things
– They are digitally signed applets, which can ask user if he/she allows
to do something. See the keytool program in JDK.
Java course – IAG0040 Lecture 14
Anton Keks Slide 13
14. Deployment of Applets
● The special <applet> HTML tag is used
– <applet code=”MyApplet.class” width=”10” height=”10”>
<param name=”myparam” value=”avalue”/>
</applet>
– Additional attributes:
● codebase – defines either relative of absolute URL where class files
are located
● archive – can specify jar file(s), where to load classes and other
files from
Java course – IAG0040 Lecture 14
Anton Keks Slide 14
15. Applet task
● Create CommentApplet
● Use CommentBean there
● Use Applet parameters for customization of
background color and comment
● Create an text field and use it for changing the
comment String at runtime
● Display the java-logo.gif within the Applet by using
getImage(getCodeBase(), “filename”) and
g.drawImage(img, 0, 0, this)
● Deploy applet and view using a web browser
Java course – IAG0040 Lecture 14
Anton Keks Slide 15
16. JFC
●
JFC = Java Foundation Classes
●
Includes
– Swing GUI Components
– Pluggable look-and-feel support
– Accessibility API
– Java2D API
– Drag-and-drop support
– Internationalization
●
JFC/Swing currently is the most popular GUI toolkit
Java course – IAG0040 Lecture 14
Anton Keks Slide 16
17. Hello, Swing!
● public class HelloSwing {
private static void createAndShowGUI() {
JFrame frame = new JFrame("HelloSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel("Hello, Swing!");
frame.add(label);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
}
} }
Java course – IAG0040 Lecture 14
Anton Keks Slide 17
18. Swing concepts
●
Containers contain other components
– Top-level (JApplet, JDialog, JFrame), they have contentPane
(e.g. JPanel) and optional JMenuBar
– General-purpose (JPanel, JScrollPane, JSplitPane, JTabbedPane,
JToolBar, etc)
– containers provide add() methods
● Layouts control positions of child components
● Most noncontainer components have optional Model interfaces (e.g.
ButtonModel), which can store their state (think of MVC pattern)
●
The overall design follows JavaBeans conventions, including the
event handling mechanism
Java course – IAG0040 Lecture 14
Anton Keks Slide 18
19. Swing & Concurrency
● Most of the API is not thread-safe
– Thread-safe parts are documented so
●
Swing and AWT use their own event dispatch thread
– most interactions with GUI components should happen
there
– SwingUtilities class provides invokeLater() and
invokeAndWait()
– event handling code must be as short as possible
●
Longer running code must be in separate threads
– this allows GUI to always stay responsive, avoids freezing
– Java 1.6 introduced SwingWorker to simplify this
Java course – IAG0040 Lecture 14
Anton Keks Slide 19
20. Swing Tips
●
JOptionPane provides various simple dialog boxes
– showMessageDialog – shows a message box with an OK button
– showConfirmDialog – shows a confirmation dialog with Yes,
No, Cancel, etc buttons
– showInputDialog – shows a dialog for entering text
● Look-and-feel is controlled by the UIManager
– UIManager.setLookAndFeel(“com.sun.java.swing.plaf.”
+ “motif.MotifLookAndFeel");
– UIManager.setLookAndFeel(UIManager.
getSystemLookAndFeelClassName());
– UIManager.setLookAndFeel(UIManager.
getCrossPlatformLookAndFeelClassName());
Java course – IAG0040 Lecture 14
Anton Keks Slide 20
21. SWT
●
SWT == Standard Widget Toolkit
● Fast, portable, native (uses native “themes”)
●
Implemented in Java using native Java adapters
●
API is a bit less flexible than Swing, not 100% JavaBean-compatible
● UI access is strictly single-threaded
●
Not included in standard distribution, must be deployed manually
Java course – IAG0040 Lecture 14
Anton Keks Slide 21
22. Hello, SWT!
● public class HelloSWT {
public static void main (String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Label label = new Label(shell, SWT.BORDER);
label.setText(“Hello, SWT!”);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose ();
}
}
Java course – IAG0040 Lecture 14
Anton Keks Slide 22
23. SWT concepts
●
Containers contain other components
– Top-level container is Shell, which is a Composite
– Widget constructors take parent Composite as a parameter. No
relocations or multiple parents.
– All widgets take style bits in constructors, which can be
composed
Button btn = new Button(shell, SWT.PUSH | SWT.BORDER);
● Display class provides the environment
● Layouts control positions of child components, each control can have its
LayoutData assigned
● Not all API conforms to the JavaBeans conventions; event handling
mechanism is pretty standard
● All widgets must be manually dispose()d! Parent disposes its children.
Java course – IAG0040 Lecture 14
Anton Keks Slide 23
24. SWT & Concurrency
●
The Thread that creates the display becomes
the user-interface Thread (aka event-
dispatching thread)
– other threads cannot access UI components
– Display provides methods to ease this task
● asyncExec, syncExec, timerExec – they all execute
provided Runnable implementation in the UI thread
● Event loop must be executed manually
– Display.readAndDispatch() in a loop
●
processes events on native OS's queue
Java course – IAG0040 Lecture 14
Anton Keks Slide 24
25. GUI task
● Write a simple CalculatorApplication
using either Swing or SWT
● It must have number buttons from 0 to 9, +, -, *,
/, =, and Clear. Label must be used for
displaying the current number or the result.
● Note: IDEA's Frame Editor can help :-)
Java course – IAG0040 Lecture 14
Anton Keks Slide 25