Ancora su repaint… Quando si modifica la composizione di un container, per mostrare le variazioni NON BASTA chiamare la repaint(), prima occorre chiamare.

Slides:



Advertisements
Similar presentations
Custom Painting Gestione della Grafica customizzata Vedi anche:
Advertisements

Fondamenti di Java Introduzione alla costruzione di GUI (graphic user interface)
Layouts and Graphics. component - container - layout Un Container contiene [0 o +] Components Il Layout specifica come i Components sono disposti nel.
Custom Painting Gestione della Grafica customizzata Vedi anche:
Inner Classes Ancora eventi. 2 Design considerations The most important rule to keep in mind about event listeners that they should execute very quickly.
User Interfaces II GUI – Awt, Swing, Web
17 Copyright © 2005, Oracle. All rights reserved. Deploying Applications by Using Java Web Start.
Chapter 15 Graphics. To paint, you need to specify where to paint. Each component has its own coordinate system with the origin (0, 0) at the upper-left.
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Made with love, by Zachary Langley Applets The Graphics Presentation.
Computer Science 209 Images and GUIs. Working with Java Colors The class java.awt.Color includes constants, such as Color.red, for some commonly used.
Web Design & Development Lecture 19. Java Graphics 2.
Frame Windows A frame object is used to create a graphical frame window. This frame is used to show information in a graphical application. The JFrame.
Java Applets:. How Applets differ from application?: They do not use main method but init(), start() and paint() methods of the applet class They can.
Examples. // A simple Frame with Rectangle Inside import java.awt.*; import javax.swing.*; import java.awt.geom.*; // For Shapes class rectComponent extends.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Graphics Chapter 16.  If you want to draw shapes such as a bar chart, a clock, or a stop sign, how do you do it?
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Chapter 5 Programming Graphics. Chapter Goals To be able to write simple applications To display graphical shapes such as lines and ellipses To use colors.
Multithreading : animation. slide 5.2 Animation Animation shows different objects moving or changing as time progresses. Thread programming is useful.
Chapter 5 Programming Graphics. Chapter Goals To be able to write applications with simple graphical user interfaces To display graphical shapes such.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 3.
Java Applets- Using SwingWorker Dave Price and Chris Loftus Computer Science Department University of Wales, Aberystwyth.
1 Configuring Internet- related services (April 22, 2015) © Abdou Illia, Spring 2015.
Graphics Programming With Applets Feb 23, Applets There are three different types of executable java code. –Standalone application, which has main()
Carnegie Mellon University, MISM1 Java GUI programming and Java Threads GUI example taken from “Computing Concepts with Java 2” by Cay Horstmann Thread.
Object Oriented Programming Java 1 GUI example taken from “Computing Concepts with Java 2” by Cay Horstmann GUI Programming.
Java ThreadsGraphics Programming Graphics Programming: Java Threads.
Current Topics in Programming Languages Lecture 15_1 George Koutsogiannakis SUMMER
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
JSP and Servlets Lecture notes by Theodoros Anagnostopoulos.
Java: Chapter 1 Computer Systems Computer Programming II Aug
Tutorial 11 Installing, Updating, and Configuring Software
1 Guide to Novell NetWare 6.0 Network Administration Chapter 11.
Java: Chapter 1 Computer Systems Computer Programming II.
19-Sep-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Applets Maj Joel Young
CN1260 Client Operating System Kemtis Kunanuraksapong MSIS with Distinction MCT, MCITP, MCTS, MCDST, MCP, A+
IT 211 Project Integration and Deployment Lab #11.
Implementation - Deployment Methods of deployment –User PC –Network shared (workstation install) –Terminal server –Web Deployment (ActiveX) (Note: this.
Standalone Java Application vs. Java Web Application
Applets and Frames CS 21a: Introduction to Computing I First Semester,
1 Introduction to Applets. 2 Applications Programs that execute using the java interpreter Executes in command windows.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Microsoft FrontPage 2003 Illustrated Complete Finalizing a Web Site.
Not all java code is an application! Applets, Webstart and Servlets Warning: this is just to show you where to look and some things to look for – by no.
MCTS Guide to Microsoft Windows Server 2008 Applications Infrastructure Configuration (Exam # ) Chapter Four Windows Server 2008 Remote Desktop Services,
Tools Menu and Other Concepts Alerts Event Log SLA Management Search Address Space Search Syslog Download NetIIS Standalone Application.
Java Applets. Topics What is an applet? To convert GUI applications to Applets Hello World applet example!! Applets life cycle examples Invoking applets.
Canvas and Graphics CS 21a. 9/26/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L17: Canvas.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Pravin Yannawar, DOCS, NMU Jalgaon Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications.
Proprietary & Confidential Java WebStart Created by Bob Hays.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Creating Applets. What is an applet? What is an applet? A Java program that runs in a web browser. A Java program that runs in a web browser. An applet.
Installing SAS 1. Requirements If you do not have an old copy of SAS installed on your computer, go directly to Slide 6. Make sure you have uninstalled.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Chapter 13: Multithreading The Thread class The Thread class The Runnable Interface The Runnable Interface Thread States Thread States Thread Priority.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Using CVUSD Print Center Desktop Printer Chino Valley Unified School District.
Today Threading, Cont. Multi-core processing. Java Never Ends! Winter 2016CMPE212 - Prof. McLeod1.
ClickOnce Deployment (One-click Deployment)
Running a Forms Developer Application
Chapter 13: Multithreading
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
JCreator Settings Only
ClickOnce Deployment (One-click Deployment)
Presentation transcript:

Ancora su repaint… Quando si modifica la composizione di un container, per mostrare le variazioni NON BASTA chiamare la repaint(), prima occorre chiamare la validate().

Ancora su repaint… p.addButton(); p.validate(); p.repaint();

Animazione in Java Problemi che possono nascere, e loro soluzione

Animazione in Java Application MyFrame (JFrame) ClockPanel (JPanel)

ClockPanel - paintComponent public class ClockPanel extends JPanel { … public void paintComponent(Graphics g) { Date d=new Date(); int sec=d.getSeconds(); double angle=sec*Math.PI/30; int w=this.getWidth(); int h=this.getHeight(); g.setColor(Color.YELLOW); g.fillRect(0,0,w,h); g.setColor(Color.GREEN); g.fillOval(0,0,w,h); g.setColor(Color.BLACK); g.drawLine(w/2,h/2, (int)(w/2*(1+Math.cos(angle))),(int)(h/2*(1+Math.sin(angle)))); } … OBSOLETO, ma funziona

MyFrame – version 1 public class MyFrame extends JFrame { //Component initialization private void jbInit() throws Exception { contentPane=new ClockPanel(); this.setContentPane(contentPane); contentPane.setLayout(borderLayout1); this.setSize(new Dimension(400, 300)); this.setTitle("Frame Title"); while (true) { try { Thread.sleep(1000); } catch (InterruptedException ex) { } contentPane.repaint(); }... Sembra ok, ma NON FUNZIONA!

Animazione e Threads in Java Application MyFrame (JFrame) ClockPanel (JPanel) Runner (Runnable)

Runner public class Runner implements Runnable { ClockPanel cp; public Runner(ClockPanel cp) { this.cp=cp; } public void run() { while (true) { try { Thread.sleep(1000); } catch (InterruptedException ex) { } cp.repaint(); }

MyFrame – version 2 public class MyFrame extends JFrame { //Component initialization private void jbInit() throws Exception { contentPane=new ClockPanel(); this.setContentPane(contentPane); contentPane.setLayout(borderLayout1); this.setSize(new Dimension(400, 300)); this.setTitle("Frame Title"); Runner r=new Runner(contentPane); new Thread(r).start(); }...

Applicativi in Java Come distribuire un applicativo fatto in Java? Vedi anche

JRE? What is that? What version? the author of a Java program has to ensure that the proper version of the JRE is installed on an end user system. In a general case you may not expect that your end users will know what a JRE is, how to check its version, and how to download and install it.

A.bat file (or a.sh file) Even if you can make sure the right version of the JRE is properly installed on enduser systems, which is quite possible in a classroom or enterprise environment, the command line required to launch your Java application can be quite long: java -Xmx200m -cp whatever.jar -Dsome.property MyApp Yes, you may put that line into a batch file and call it runme.bat, but it looks so much easier to give your program to a friend, teacher or colleague as a single file that can be run by a double-click. Or, even better, enable it to be installed and uninstalled in a native manner without affecting other applications.

executable jar you can make your Java application runnable via a double-click by packaging it into a so called executable jar You do that by specifying the main class of your application, any extra jar files it may require and so on in the jar's manifest file MANIFEST.MF Manifest-Version: 1.0 Main-Class: animation.Application1

executable jar Crea un jar: jar cvfm MyApp.jar MyApp.mf *.class *.gif Esegui un jar: java -jar MyApp.jar the Java launcher will read the manifest from MyApp.jar and invoke the main method from the class specified in the Manifest. If you double-click that jar file on a system that has JRE installed, the java launcher will be invoked automatically.

JAR problems The major problem with executable jars is compatibility. The default JRE may be of an older version than is required by your application or may not have the necessary Java Optional Packages installed.

JWS - Java Web Start Using Java Web Start technology, standalone Java software applications can be deployed with a single click over the network. Java Web Start ensures the most current version of the application will be deployed, as well as the correct version of the Java Runtime Environment (JRE). Java Runtime Environment (JRE) Java Web Start downloads, installs, and manages one or more Java Runtime Environments as required by the applications the user runs.

JWS - Java Web Start After running the application for the first time from the web page as described above, the application is cached. This both improves application performance and enables the user to access it without returning to the web page. The application is added to the Java Application Cache Viewer. Users can simplify running a Java Web Start application further by adding a shortcut to the desktop, by selecting Install Shortcuts from the Application menu in the Java Application Cache Viewer.

JWS - Java Web Start Developer responsibilities: - Crea un JAR file - Crea un JNLP file - Crea una Web Page - Metti il tutto su un Web Server

JWS - JNLP file <jnlp spec="1.0 codebase="URL of application on your Web server" href="Notepad.jnlp"> Notepad Demo Sun Microsystems, Inc. <j2se version="1.3+" href="

JWS - Java Web Start Where Do You Get Java Web Start? Java Web Start is included in the Java Runtime Environment (JRE) as part of J2SE 5.0.Java Runtime Environment (JRE)J2SE 5.0 Vedi

Custom wrappers When a Java program is invoked the operating system runs a Java launcher from the JRE. The Windows version of the JRE has separate launchers for command-line and GUI apps, called java.exe and javaw.exe respectively. As a result, all running Java applications have the same Taskbar/Alt- Tab icons and appear in the Windows Task Manager as either java.exe or javaw.exe. If you have two or more Java apps running, you have no means to distinguish between multiple instances of the standard Java launcher in the Task Manager.

Custom wrappers A Java wrapper in essentially a custom Java launcher that is also a self-extracting archive containing all the application's classes, jars and auxiliary files. Some wrapper provide additional features such as instant splash screen, stdout and stderr redirection. A wrapper normally looks up the JRE upon startup. If the JRE is not present or its version does not match the application's compatibility requirements, some wrappers may install the JRE (if you have included it when wrapping your application) and/or download and install the required version of the JRE. The most sophisticated wrappers may also setup file associations and create shortcuts on first run.

Custom wrappers Pro JRE version check JRE download or bundling Unique process name and icon No end-user training Contro Platform specific Desktop integration capabilities absent or very limited Per una lista di Wrappers (free o commerciali) vedi

Installers Installer tools may give you the following benefits: * Install-time JRE detection and download * Generation of native launchers * User-editable JVM parameter files * Redirection of stderr and stdout for saving logs and exception stack traces. * Registration of Java applications as Windows services and Unix daemons Platform-centric, Multi-Platform, Cross-Platform free: IzPack, Advanced Installer for Java

Ahead-Of-Time Compilers AOT compilers are known also as "static compilers" and "native code compilers". The latter term is the most used and, as it often happens, the least correct from the technical standpoint, because JIT compilers also produce native code. An Ahead-Of-Time (AOT) compiler takes as input your jars and class files and produces a conventional native executable for the target platform, such as Windows EXE or Linux ELF binary. NON SERVE LA JRE!

Ahead-Of-Time Compilers Pro Peformance increase IP protection Better user perception Contro Disk footprint increase Limited applicability Vedi: 1 prodotto commerciale, 1 open source (immaturo)