How To Program In Java (Ipt) With A Bean And An Animated Object In A Powerpoint (For A Powerbook)

Similar documents
LAYOUT MANAGERS. Layout Managers Page 1. java.lang.object. java.awt.component. java.awt.container. java.awt.window. java.awt.panel

Java is commonly used for deploying applications across a network. Compiled Java code

How To Write A Program For The Web In Java (Java)

Essentials of the Java Programming Language

method is never called because it is automatically called by the window manager. An example of overriding the paint() method in an Applet follows:

How to Convert an Application into an Applet.

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

Essentials of the Java(TM) Programming Language, Part 1

CSC 551: Web Programming. Spring 2004

Interactive Programs and Graphics in Java

Mobile Application Languages XML, Java, J2ME and JavaCard Lesson 04 Java

The Abstract Windowing Toolkit. Java Foundation Classes. Swing. In April 1997, JavaSoft announced the Java Foundation Classes (JFC).

Mouse Event Handling (cont.)

Fachbereich Informatik und Elektrotechnik Java Applets. Programming in Java. Java Applets. Programming in Java, Helmut Dispert

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

TABLE OF CONTENTS...2 INTRODUCTION...3 APPLETS AND APPLICATIONS...3 JAVABEANS...4 EXCEPTION HANDLING...5 JAVA DATABASE CONNECTIVITY (JDBC)...

GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012

Computing Concepts with Java Essentials

The Darwin Game 2.0 Programming Guide

History OOP languages Year Language 1967 Simula Smalltalk

11. Applets, normal window applications, packaging and sharing your work

Assignment # 2: Design Patterns and GUIs

Mobile App Tutorial Animation with Custom View Class and Animated Object Bouncing and Frame Based Animation

JAVA. EXAMPLES IN A NUTSHELL. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo. Third Edition.

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

The Basic Java Applet and JApplet

How Scala Improved Our Java

Event processing in Java: what happens when you click?

Swing. A Quick Tutorial on Programming Swing Applications

There are some important differences between an applet and a standalone Java application, including the following:

Generating Automated Test Scripts for AltioLive using QF Test

Java applets. SwIG Jing He

SE 450 Object-Oriented Software Development. Requirements. Topics. Textbooks. Prerequisite: CSC 416

Tutorial: Time Of Day Part 2 GUI Design in NetBeans

Creating a 2D Game Engine for Android OS. Introduction

public class Craps extends JFrame implements ActionListener { final int WON = 0,LOST =1, CONTINUE = 2;

Introduction to Java Applets (Deitel chapter 3)

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Chapter 1 Learning to Program With Alice

GUI Components: Part 2

How to develop your own app

Practical Android Projects Lucas Jordan Pieter Greyling


WEEK 2 DAY 14. Writing Java Applets and Java Web Start Applications

Mobile App Development Using App Inventor

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Collaborative GeoGebra

Sample Turtle Programs

Android Application Development Course Program

Nexawebホワイトペーパー. Developing with Nexaweb ~ Nexaweb to Improve Development Productivity and Maintainability

Object Oriented Programming with Java. School of Computer Science University of KwaZulu-Natal

How to create a Flash banner advert in DrawPlus X2

Applets, RMI, JDBC Exam Review

Source Code Translation

Printing Guide. MapInfo Pro Version Contents:

Syllabus for CS 134 Java Programming

CMSC 132: Object-Oriented Programming II. Design Patterns I. Department of Computer Science University of Maryland, College Park

Flash MX Image Animation

Japan Communication India Skill Development Center

Fundamentals of Java Programming

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

MapInfo Professional Version Printing Guide

Specialized Programme on Web Application Development using Open Source Tools

JAVA DEVELOPER S GUIDE TO ASPRISE SCANNING & IMAGE CAPTURE SDK

Use fireworks and Bonfire night as a stimulus for programming

Demo: Embedding Windows Presentation Foundation elements inside a Java GUI application. Version 7.3

Java SE 6 Update 10. la piattaforma Java per le RIA. Corrado De Bari. Sun Microsystems Italia Spa. Software & Java Ambassador

Using A Frame for Output

Experiences with 2-D and 3-D Mathematical Plots on the Java Platform

Option nv, Gaston Geenslaan 14, B-3001 Leuven Tel Fax Page 1 of 14

How to Develop Accessible Linux Applications

@ - Internal # - Online TH PR OR TW TOTAL HOURS # @ 175

10 Java API, Exceptions, and Collections

Ad Hoc Reporting. Usage and Customization

WIX - Really Flashy Websites For Free

Oracle Forms Developer 10g: Build Internet Applications

For Introduction to Java Programming, 5E By Y. Daniel Liang

Japan Communication India Skill Development Center

understand how image maps can enhance a design and make a site more interactive know how to create an image map easily with Dreamweaver

5.17 GUI. Xiaoyi Jiang Informatik I Grundlagen der Programmierung

Mobile Web Design with HTML5, CSS3, JavaScript and JQuery Mobile Training BSP-2256 Length: 5 days Price: $ 2,895.00

Inspiring Creative Fun Ysbrydoledig Creadigol Hwyl. Web Design in Nvu Workbook 1

Taleo Enterprise. Career Section Branding Definition. Version 7.5

Tutorial Reference Manual. Java WireFusion 4.1

How to Write a plugin for JMeter

Specialized Programme on Web Application Development using Open Source Tools

12Planet Chat end-user manual

Elements of Advanced Java Programming

Object-Oriented Programming and Data Structures

Using NetBeans IDE to Build Quick UI s Ray Hylock, GISo Tutorial 3/8/2011

UniFLOW Print and Copy Instructions for Students

Transcription:

Graphic Interface Programming II Applets and Beans and animation in Java IT Uppsala universitet

Applets Small programs embedded in web pages <applet width=300 height=300 code="drawinglines.class"> </applet> 5/5/11 #2

Applets don t Swing Some things have to be done differently No Constructor init( ) No main method the browser starts the applet No Swing paintcomponent(graphics g) paint(graphics g) Less complex programs no Frames The web page embeds the Applet (For using Swing Components JApplet) 5/5/11 #3

// Simple Applet class // public class DrawingLine extends Applet { // Keeps knowledge of the size of the Applet // int width, height; public void init() { width = getsize().width; height = getsize().height; setbackground( Color.black ); } } // In the paint method we just define a simple loop that paints ten // green lines over the black background. // public void paint( Graphics g ) { g.setcolor( Color.green ); for ( int i = 0; i < 10; ++i ) { g.drawline( width, height, i * width / 10, 0 ); } } 5/5/11 #4

Alternative to Flash Good or Bad? Good Java programmer might have advantage Not all platforms have Java installed Some browser have Java deactivated by default Security issues Need to consider bad and good aspects 5/5/11 #5

Still Powerful Graphics Display Does not work on all platforms As you well know Even if Java is implemented 5/5/11 #6

JavaBeans GUI Builders use a certain type of class A Bean is a class that follows certain rules It has to have a public default constructor (no arguments) It has to have specific getter and sette functions to access its properties It should be serializable (possible to save in any state) A Bean can be used as a jsp-object 5/5/11 #7

GUI Builders JavaBeans are important for GUI Builders Builders use the concept of Introspection The Introspector class can examine a bean for design patterns Create your own Swing objects as Beans Can be added as Graphic objects in the Builder 5/5/11 #8

Example import java.awt.color; import java.beans.xmldecoder; import javax.swing.jlabel; import java.io.serializable; public class SimpleBean extends JLabel implements Serializable { public SimpleBean() { settext( "Hello world!" ); setopaque( true ); setbackground( Color.RED ); setforeground( Color.YELLOW ); setverticalalignment( CENTER ); sethorizontalalignment( CENTER ); } } 5/5/11 #9

SimpleBean Extends JLabel a Visual Component Implements Serializable (or Externalizable) The Introspection feature allows the SimpleBean to have properties that can be changed Can be found in the Beans tab in NetBeans (I am not sure about Eclipse). 5/5/11 #10

Animation Good example of a Design Pattern How to ensure OOP principles? 5/5/11 #11

Purpose of Animation Driver One or more Animations Simulation Realtime game (e.g. Battlebots) Other dynamic realtime animation with several animated objects One Actor controls the Animation process Singleton (suggested by one group) Controls Animation Progress 5/5/11 #12

Decisions? The amount of control in driver? Different animation speeds? Which objects to animate? How is the driver controlled? 5/5/11 #13

OOP Principle The driver needs to be free of knowledge about the respective animations Each animated object responsible for its own animation, e.g.: Driver controls general animation speed Animated object controls its own relative animation speed 5/5/11 #14

Animator Pattern Interface AnimatedObject One primary method: tick() Each tick is one cycle in general Animation Animator Tracks (manages) the animated objects Sends ticks to all its Animated Objects Methods: addobject(animatedobject ao) removeobject(animatedobject ao) ao.tick() // sends ticks to all animated objects 5/5/11 #15

Animator Pattern Animated Object could be any class As long as it implements the AnimatedObject interface Does not have to be a graphic component! In fact it is easier to draw if it is not A panel can host many animated graphics defines only paintcomponent(graphics g)! the graphic adds its own drawing to the Graphics environment! 5/5/11 #16

Animated Graphics Uses the paintcomponent of (e.g.) Jpanel Implements Drawable interface: method: draw(graphics g) the method should specify the graphic commands for the graphic Does not specify the paintcomponent is not a Component, but a loose graphic 5/5/11 #17

Jpanel paintcomponent Each Drawable object implements the draw() method. @Override public void paintcomponent(graphics g) { Drawable d; for (Iterator<?> it = graphicobjects.iterator(); it.hasnext(); ) { d = (Drawable) it.next(); d.draw(g); } } 5/5/11 #18

Complex graphics Every graphic uses draw(graphics g) to add itself to the graphics environment A single call to paintcomponent() 5/5/11 #19

Animated Complex Graphics If we want to implement graphics that move, the class has to implement both interfaces. public class MovingStar implements Drawable, AnimatedObject { } //here the drawing is made in //draw(graphics g) 5/5/11 #20

Animation Process Create graphic Container (JPanel?) Collect all graphic objects (not Swing Components) For every tick: update the graphic objects (position, size, colour, etc.) In paintcomponent(graphics g) draw all graphic objects on the Graphics environment g 5/5/11 #21

Trick for animation (snake) Use a suitable data structure that can be used as a QUEUE First in first out actions Push new graphic objects onto the QUEUE Pop old ones from the QUEUE If time is used for popping varying length of tail 5/5/11 #22