Docsity

Slides on More Java for Real - Computer Expressive Medium | LCC 6310, Study Guides, Projects, Research of Communication

Toggle sidebar
bg1
1
LCC 6310
The Computer as an
Expressive Medium
Lecture 25
Overview
Project 6 assigned
More Java for real!
Graphical Java applications - double buffering!
Mouse listeners
Braitenberg vehicles revisited
Project 6
Due: Friday December 7
While computer-based interactive games (a.k.a. video games) have
been a pop-cultural force since the arcade scene of the late 1970s
and early 1980s, in recent years video games have been recognized
as a major emerging art form, poised to have as much cultural
impact on the 21st century as cinema did on the 20th. The game
industry is making Hollywood-sized amounts of money, with
designers of the most popular games achieving a geeky sort of
celebrity. Museums and galleries are offering exhibitions of "art
games", computer-scientists are beginning to treat games as
technical objects worthy of serious attention, and in humanities
departments around the world, games studies is a hot new topic.
What kind of game would you create? Create a simple game. Your
game should be a "regular" Java applet (i.e. do not use Processing).
Java reminder
Use your favorite text editor to write your Java code. To compile,
package and run a Java application:
Step 0: Write source code for your java classes in text editor and
create a manifest file which describes the main class
Step 1: Compile your .java files
> javac *.java
Step 2: Package your .class files into a .jar
> jar -cfm MyJar.jar MyManifest.txt *.class
Step 3: Run your java application using the .jar
> java -jar MyJar.jar
Note: for java applets, you don't need a Manifest and you can view
your applet by putting it on a webpage.
pf3
pf4
pf5

Partial preview of the text

Download Slides on More Java for Real - Computer Expressive Medium | LCC 6310 and more Study Guides, Projects, Research Communication in PDF only on Docsity!

LCC 6310The Computer as anExpressive MediumLecture 25

Overview

Project 6 assignedMore Java for real!Graphical Java applications - double buffering!Mouse listenersBraitenberg vehicles revisited

Project 6

Due: Friday December 7While computer-based interactive games (a.k.a. video games) havebeen a pop-cultural force since the arcade scene of the late 1970sand early 1980s, in recent years video games have been recognizedas a major emerging art form, poised to have as much culturalimpact on the 21st century as cinema did on the 20th. The gameindustry is making Hollywood-sized amounts of money, withdesigners of the most popular games achieving a geeky sort ofcelebrity. Museums and galleries are offering exhibitions of "artgames", computer-scientists are beginning to treat games astechnical objects worthy of serious attention, and in humanitiesdepartments around the world, games studies is a hot new topic.What kind of game would you create? Create a simple game. Yourgame should be a "regular" Java applet (i.e. do not use Processing).

Java reminder

Use your favorite text editor to write your Java code. To compile,package and run a Java application:Step 0: Write source code for your java classes in text editor andcreate a manifest file which describes the main classStep 1: Compile your .java files^ > javac^ *.java Step 2: Package your .class files into a .jar^ > jar -cfm MyJar.jar

MyManifest.txt *.class

Step 3: Run your java application using the .jar^ > java^ -jar^ MyJar.jar Note: for java applets, you don't need a Manifest and you can viewyour applet by putting it on a webpage.

Graphical java

Graphical java applet reminder The AWT is the Java Abstract Windowing Toolkit - a package thatprovides all sorts of classes for creating graphical applicationsWindows, panels, canvases, menus, fonts, images etc.Component is a graphical object that can be displayed on-screen andthat can interact with the userComponent's paint method is called by the System whenever thecomponent needs to be painted. Use repaint to schedule a paint callYou can override the paint method in a Component subclass to describehow it should be paintedApplet extends Panel which is a Component, so Applet can overridethe paint methodWe tried the other week in HelloGraphicsApplet…

import^ java.applet.;import^ java.awt.;public^ class^ HelloGraphicsApplet

extends^ Applet^ { int^ w,h;^ //^ applet^ sizeString^ hellostr^ =^ "Hello world!";^ //^ hello^ string int^ sw,^ sh,^ sx,^ sy;^ //^ hello

string^ size^ and^ position public^ void^ init()^ { setBackground(Color.black);w^ =^ Integer.parseInt(getParameter("width"));h^ =^ Integer.parseInt(getParameter("height"));}public^ void^ paint(Graphics

g)^ { FontMetrics^ fm^ =^ g.getFontMetrics();

//^ get^ our^ string^ size^

info

sw^ =^ fm.stringWidth(hellostr);sh^ =^ fm.getHeight();g.setColor(Color.red);g.drawString(hellostr,(w-sw)/2,h/2);} } Let's look at the HelloGraphicsApplet.java file…

Let's turn this into an application… To do this we need to do the following:Instead of extending Applet, we can extend PanelDecide how big our Panel should beWe can override the getMinimumSize and getPreferredSize methods to make sure itnever gets displayed at any other size…Override the paint method so that we can paint our textPut our Panel in a Frame (top-level window to be displayed on screen)Before trying this, let's look at one new concept - double buffering!

Braitenberg vehicles revisited

Moving to java applets First let's try the sensory field applet:Remember that a sensory field of light sources contains two classes inaddition to the main applet class:Source.javaSensoryField.javaThen we can expand to a complete Braitenberg vehicles applet:The classes we'll need to add for this are:Vehicle.java (and VehicleCoward.java, VehicleAggressive.java, etc.)Sensor.javaWheel.java

Sensory Field

Let's revisit the Processing implementation of the sensory field appletto see what needs to be changed:Source.javaThis is mostly okay, except that it draws itself onto a Processing appletdisplay. We can draw into a Graphics object instead.SensoryField.javaLike the sources, the sensory field should draw itself into a Graphicsobject instead of a PApplet.The sensory field also stores the ground as a PImage. We can insteaduse a MemoryImageSource. This class uses an array to produce pixelvalues for an image. It can also manage memory images that changeover time (i.e. animations).Let's look at these classes and at SFApplet.java, and run the applet…

Braintenberg Vehicles Let's revisit the Processing implementation of the braitenberg vehicleapplet to see what needs to be changed:Sensor.java, Vehicle.java, Wheel.javaLike Source and SensoryField, these should all draw themselves intoGraphics objects instead of PApplets.BVApplet.javaIn the Processing implementation, the vehicles are drawn in the draw()loop, but we don't have one here. Where do we trigger the call torepaint?Let's look at these classes and run the applet…

Remember…

This Thursday is Thanksgiving!Happy Thanksgiving! (and no readings…)But for next Thursday: Theory Readings…Two students: present one reading eachEveryone else: prepare one discussion question for each readingThe Lessons of Lucasfilm's Habitat - Morningstar & Farmer (NMR pp.663-678)The Work of Culture in the Age of Cybernetic Systems - Nichols (NMR pp.625-642)