java for desktop

25
Java for Desktop @t4ffer @toomasr Tartu 2012

Upload: others

Post on 07-Apr-2022

6 views

Category:

Documents


0 download

TRANSCRIPT

Java for Desktop

@t4ffer @toomasrTartu 2012

Desktop?

● GUI Apps● Multimedia● Java in a Browser?● 2D/3D Apps, Games

GUI Apps: Toolkits

● What's a toolkit?● Building blocks for GUIs (Widgets, Windows)● Toolkit vs. Framework

– Toolkit: you call toolkit API

– Framework: framework calls your code

● Toolkits: AWT, Swing, SWT● Frameworks: JavaFX

GUI Toolkits: AWT

● Abstract Window Toolkit– Windowing toolkit– Graphics toolkit– User interface widget toolkit (quite old)

● Platform independent– Also the GUI for number of Java ME profiles

GUI Toolkits: AWT

GUI Toolkits: Swing

● Primary widget toolkit (replaces AWT)● Written in Java (AWT is not)● Pluggable Look & Feels

– Includes native-like Look & Feel

● Not platform-specific

GUI Toolkits: Swing

GUI Toolkits: SWT

● From IBM, now under Eclipse Foundation● Native + Custom Components● Implemented in native libraries, platform-

specific– Native Look & Feel

● Java Widget objects have „native peers“– Have to manually dispose objects

GUI Toolkits: SWT

GUI Apps: JavaFX

● Scene-graph based UI Framework● Positioned as the new primary GUI story

GUI Apps: JavaFX

GUI Apps: Layouts

● Absolute– specify positions in coordinates

● FillLayout– make components fill the container

● GridLayout– Lay out components on a grid

● GridBagLayout– More flexible grid layout

● JGoodies - http://www.jgoodies.com/●

GUI Apps: Rich Client Platforms

● Frameworks, not Toolkits● Eclipse RCP

– GUI: SWT + JFace + Workbench

– Modularity: OSGi

● NetBeans RCP– GUI: Swing

– Modularity: OSGi or NetBeans Platform Modules

GUI Apps: Examples

● SWT– Eclipse

– Vuze

● Swing– IntelliJ IDEA, NetBeans

– SoapUI, JMeter

– FreeMind

Visual Editors: NetBeans GUI Builder

● For Swing● Formerly known as „Matisse“● Very easy to layout Swing components● Doesn't understand hand-written code

– Saves an XML file along with the code – these need to be in sync

– Locks down sections of the code in the code editor

Visual Editors: Eclipse WindowBuilder

● For Swing, SWT, Eclipse RCP– Seems to be very slow for Swing

● Understands hand-written code– Switch between visual & code editing at will

– Still have to be careful and keep code structure „normal“

● Can't always copy & paste UI components

Multimedia

● Imaging– javax.imageio

– Java2D

– Java Advanced Imaging

● Sound– javax.sound

– OpenAL bindings in LWJGL

● Java Media Framework API (JMF)

Java in Browser?

● Applet – runs in a browser window– Sandboxed

● Java Web Start – launched from browser– Runs in a separate window

– Sandboxed

– Signed applications can obtain elevated permissions

– Automatic updates

Java Web Start (JNLP)

● Example .jnlp file<?xml version="1.0" encoding="UTF-8"?><jnlp spec="1.0+" codebase="http://ultrastudio.org/upload" href=""> <information> <title>Launch applet with Web Start</title> <vendor>Foo Bar Inc.</vendor> <offline-allowed/> </information> <resources> <j2se version="1.5+" href="http://java.sun.com/products/autodl/j2se"/> <jar href="Ray-2.3-4ca60e46-0956-3f22-983c-e3ed986dfd03.jar" main="true" /> </resources> <applet-desc name="Ray diagram applet" main-class="raydiagramsapplet.Main" width="300" height="200"> </applet-desc> <update check="background"/></jnlp>

3D & Games

● Java3D● OpenGL Bindings & Game Libraries

– LWJGL - http://www.lwjgl.org/● Includes audio and input libraries, not just OpenGL

– JOGL - http://jogamp.org/

– Slick - http://slick.cokeandcode.com/● 2D game library, uses LWJGL

3D Game Engines

● JMonkeyEngine - http://jmonkeyengine.com/● Ardor3D - http://ardor3d.com/

3D & Games: Performance

● Garbage Collection & Memory Management● High-performance game code needs tighter

control of memory management● Lack of value objects / structs● CPU Cache misses due to objects in arrays

not being co-located in memory

3D & Games: Performance

● Garbage Collection & Memory Management● High-performance game code needs tighter

control of memory management● Lack of value objects / structs● CPU Cache misses due to objects in arrays

not being co-located in memory

3D Performance: Workarounds

● Workaround #1: don't need high performance● Workarounds by writing non-idiomatic code

– Object-of-Arrays instead of Array-of-Objects● class Spaceships { int xs[]; int ys[]; }

– Use pooled mutable objects for what could be simple values

● GC tuning● Improvements coming in future Java versions

3D & Games: Examples

● LWJGL– Minecraft

– Blocks That Matter

● Slick– Lots of small games but didn't find any high-profile

examples