A very simple car game in Java
|
|
|
- Michael Thomas
- 9 years ago
- Views:
Transcription
1 A very simple car game in Java
2 package cargame; CarGame.java import javax.swing.*; public class CarGame { public static void main(string[] args) { // Create application fram and a game surface JFrame frame = new JFrame("Car game"); frame.setdefaultcloseoperation(windowconstants.exit_on_close); GameSurface s = new GameSurface(); // Create a few cars and assign behaviours to them Car mycar = new Car("car.png"); mycar.updateposition(450, 450); mycar.setmass(1.0f); mycar.setmaxspeed(100.0f); mycar.setmaxsteering(70.0f); mycar.addbehaviour(new RoamBehaviour(100, 100, 300, 300)); Car mycar2 = new Car("car.png"); mycar2.updateposition(50, 50); mycar2.setmass(1.0f); mycar2.setmaxspeed(120.0f); mycar2.setmaxsteering(100.0f); mycar2.addbehaviour(new PursuitBehaviour(myCar)); mycar2.addbehaviour(new BounceOffWallsBehaviour(30, 30, 470, 470)); Car mycar3 = new Car("playercar.png"); mycar3.updateposition(250, 250); mycar3.setmass(1.0f); mycar3.setmaxspeed(120.0f); mycar3.setmaxsteering(300.0f); mycar3.updatevelocity(120.0f, 0.0f);
3 PlayerSteeringBehaviour steering = new PlayerSteeringBehaviour(); mycar3.addbehaviour(steering); mycar3.addbehaviour(new BounceOffWallsBehaviour(30, 30, 470, 470)); s.addkeylistener(steering); // Add the cars to the game surface so that // they will be drawn s.getvehicles().add(mycar); s.getvehicles().add(mycar2); s.getvehicles().add(mycar3); // Display the game surface in the frame, and // make the frame visible frame.setcontentpane(s); frame.setsize(500, 500); frame.setvisible(true); // Since we want to receive keyboard events, // the game surface needs to have the input focus s.requestfocusinwindow(); // Create the animation thread and start it AnimationSystem a = new AnimationSystem(s); Thread t = new Thread(a); t.start();
4 Vehicle.java package cargame; import java.awt.*; import java.awt.geom.*; import java.util.*; public abstract class Vehicle { // Member variables protected Point2D.Float position = new Point2D.Float(); protected Point2D.Float orientation = new Point2D.Float(); protected Point2D.Float side = new Point2D.Float(); protected Point2D.Float velocity = new Point2D.Float(); protected Point2D.Float steering = new Point2D.Float(); protected float mass; protected float maxspeed; protected float maxsteering; // List of behaviours protected ArrayList behaviours = new ArrayList(10); // Getters and setters public Point2D.Float getposition() { return position; public void updateposition(point2d.float p) { position.x = p.x; position.y = p.y; public void updateposition(float x, float y) { position.x = x; position.y = y; public Point2D.Float getorientation() { return orientation; public void updateorientation(point2d.float o) { orientation.x = o.x; orientation.y = o.y; public void updateorientation(float x, float y) { orientation.x = x; orientation.y = y; public Point2D.Float getsidevector() { return side;
5 public Point2D.Float getvelocity() { return velocity; public void updatevelocity(point2d.float v) { velocity.x = v.x; velocity.y = v.y; public void updatevelocity(float x, float y) { velocity.x = x; velocity.y = y; public Point2D.Float getsteering() { return steering; public void updatesteering(point2d.float s) { steering.x = s.x; steering.y = s.y; public void updatesteering(float x, float y) { steering.x = x; steering.y = y; public float getmass() { return mass; public void setmass(float m) { mass = m; public void setmaxspeed(float m) { maxspeed = m; public float getmaxspeed() { return maxspeed; public void setmaxsteering(float f) { maxsteering = f; public float getmaxsteering() { return maxsteering; public void addbehaviour(behaviour b) { behaviours.add(b); // A few utility methods for working with vectors static float length(point2d.float v) { return (float)math.sqrt((v.x * v.x) + (v.y * v.y)); static public void scale(point2d.float v, float newlength) { float l = length(v); v.x *= newlength / l; v.y *= newlength / l;
6 // Update this vehicle public void update(float dt) { for (int i = 0; i < behaviours.size(); i++) { ((Behaviour)behaviours.get(i)).update(this, dt); // Truncate the length of the desired steering force vector Point2D.Float force = new Point2D.Float(steering.x, steering.y); float l = length(force); if (l > maxsteering) { force.x *= maxsteering / l; force.y *= maxsteering / l; // Newton's second law: steering force = mass * accelerataion Point2D.Float acc = new Point2D.Float(force.x / mass, force.y / mass); // Update velocity vector using Euler's method // and truncate its length to the maximum allowed velocity.x += dt * acc.x; velocity.y += dt * acc.y; l = length(velocity); if (l > maxspeed) { velocity.x *= maxspeed / l; velocity.y *= maxspeed / l; // Update position using Euler's method position.x += dt * velocity.x; position.y += dt * velocity.y;
7 // Set orientation to equal the velocity vector // and set the side vector accordingly l = length(velocity); if (l > 0.0f) { orientation.x = velocity.x / l; orientation.y = velocity.y / l; side.x = -orientation.y; side.y = orientation.x; // Abstract methods for drawing and intersection testing public abstract void draw(graphics2d g2); public abstract boolean intersects(vehicle v);
8 Car.java package cargame; import java.awt.*; import java.awt.geom.*; import java.awt.image.*; import javax.swing.*; public class Car extends Vehicle implements ImageObserver { protected Image img; protected float w2; protected float h2; public Car(String imagefilename) { ImageIcon iic = new ImageIcon(imageFileName); img = Transparency.makeColorTransparent(iic.getImage(), Color.black); public void draw(graphics2d g2) { AffineTransform savexform = g2.gettransform(); g2.translate(position.x, position.y); g2.rotate(math.atan2(orientation.y, orientation.x)); g2.drawimage(img, AffineTransform.getTranslateInstance(-img.getWidth(this) / 2.0, -img.getheight(this) / 2.0), this); g2.settransform(savexform); /* g2.setpaint(color.yellow); g2.drawline((int)math.floor(position.x), (int)math.floor(position.y), (int)math.floor(position.x f * side.x), (int)math.floor(position.y f * side.y)); g2.setpaint(color.blue);
9 g2.drawline((int)math.floor(position.x), (int)math.floor(position.y), (int)math.floor(position.x + velocity.x), (int)math.floor(position.y + velocity.y)); g2.setpaint(color.white); g2.drawline((int)math.floor(position.x), (int)math.floor(position.y), (int)math.floor(position.x + steering.x), (int)math.floor(position.y + steering.y)); */ public boolean imageupdate(image img, int infoflags, int x, int y, int width, int height) { return true; public boolean intersects(vehicle v) { if (v instanceof Car) { Car c = (Car)v; Point2D.Float d = new Point2D.Float(position.x - c.position.x, position.y - c.position.y); if (length(d) < 25.0f) { // Should probably compute the radius from the images instead... return true; return false;
10 GameSurface.java package cargame; import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class GameSurface extends JComponent implements MouseListener { protected ArrayList vehicles; public GameSurface() { vehicles = new ArrayList(10); addmouselistener(this); // For requesting input focus public void paint(graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension d = getsize(); g2.setpaint(new Color(91, 91, 91)); g2.fillrect(0, 0, d.width, d.height); for (int i = 0; i < vehicles.size(); i++) { Vehicle v = (Vehicle)vehicles.get(i); v.draw(g2); ArrayList getvehicles() { return vehicles;
11 public void mouseclicked(mouseevent e) { // Custom components need to request the // input focus when they are clicked, // otherwise they won't receive keyboard events requestfocusinwindow(); public void mousemoved(mouseevent e) { public void mouseexited(mouseevent e) { public void mousereleased(mouseevent e) { public void mouseentered(mouseevent e) { public void mousepressed(mouseevent e) { public void mousedragged(mouseevent e) {
12 AnimationSystem.java package cargame; import java.util.*; public class AnimationSystem implements Runnable { protected GameSurface game; public AnimationSystem(GameSurface gamesurface) { game = gamesurface; public void run() { long time = System.currentTimeMillis(); for (;;) { ArrayList vehicles = game.getvehicles(); // Update position, velocity etc. of vehicles long t = System.currentTimeMillis(); long dt = t - time; float secs = (float)dt / f; // Convert to seconds for (int i = 0; i < vehicles.size(); i++) { Vehicle v = (Vehicle)vehicles.get(i); v.update(secs); // Check for collisions for (int i = 0; i < vehicles.size(); i++) { for (int j = i + 1; j < vehicles.size(); j++) { Vehicle vi = (Vehicle)vehicles.get(i); Vehicle vj = (Vehicle)vehicles.get(j); if (vi.intersects(vj)) {
13 // Collision detected! // For now, simply reset the positions of the vehicles vi.updateposition(50, 50); vj.updateposition(450, 450); time = System.currentTimeMillis(); game.repaint(); // Sleep for a short amount of time to allow the system to catch up. // This improves framerate substantially and avoids hiccups try { Thread.sleep(20); catch (InterruptedException e) {
14 Behaviour.java package cargame; public abstract interface Behaviour { public abstract void update(vehicle v, float dt);
15 PursuitBehaviour.java package cargame; import java.awt.geom.point2d; public class PursuitBehaviour implements Behaviour { protected Vehicle target; PursuitBehaviour(Vehicle v) { target = v; public void update(vehicle v, float dt) { // Steer vehicle towards target Point2D.Float p = v.getposition(); Point2D.Float tp = target.getposition(); Point2D.Float desired_velocity = new Point2D.Float(tp.x - p.x, tp.y - p.y); Vehicle.scale(desired_velocity, v.getmaxspeed()); v.updatesteering(desired_velocity.x, desired_velocity.y);
16 RoamBehaviour.java package cargame; import java.awt.geom.point2d; public class RoamBehaviour implements Behaviour { protected long lasttargetupdate; protected Point2D.Float target = new Point2D.Float(); protected float width; protected float height; protected float x; protected float y; public RoamBehaviour(float x, float y, float width, float height) { this.x = x; this.y = y; this.width = width; this.height = height; public void update(vehicle v, float dt) { // Update target if necessary long time = System.currentTimeMillis(); if (time - lasttargetupdate > 5000) { target.x = x + (float)math.random() * width; target.y = y + (float)math.random() * height; lasttargetupdate = time; // Steer vehicle towards target Point2D.Float p = v.getposition(); Point2D.Float desired_velocity = new Point2D.Float(target.x - p.x, target.y - p.y);
17 Vehicle.scale(desired_velocity, v.getmaxspeed()); v.updatesteering(desired_velocity.x, desired_velocity.y);
18 BounceOffWallsBehaviour.java package cargame; import java.awt.geom.point2d; public class BounceOffWallsBehaviour implements Behaviour { protected float x1; protected float y1; protected float x2; protected float y2; public BounceOffWallsBehaviour(float x1, float y1, float x2, float y2) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; public void update(vehicle v, float dt) { Point2D.Float p = v.getposition(); Point2D.Float vel = v.getvelocity(); if (p.x < x1) { p.x = x1; vel.x = -vel.x; if (p.x > x2) { p.x = x2; vel.x = -vel.x; if (p.y < y1) { p.y = y1; vel.y = -vel.y; if (p.y > y2) {
19 p.y = y2; vel.y = -vel.y;
20 PlayerSteeringBehaviour.java package cargame; import java.awt.event.*; import java.awt.geom.point2d; public class PlayerSteeringBehaviour implements Behaviour, KeyListener { protected boolean steering = false; protected float direction = 1.0f; public void keypressed(keyevent e) { if (e.getkeycode() == 37) { // Cursor left steering = true; direction = -1.0f; if (e.getkeycode() == 39) { // Cursor right steering = true; direction = 1.0f; public void keyreleased(keyevent e) { steering = false; public void keytyped(keyevent e) { public void update(vehicle v, float dt) { if (steering) { Point2D.Float side = v.getsidevector(); Point2D.Float desired_velocity = new Point2D.Float(side.x * direction, side.y * direction); Vehicle.scale(desired_velocity, v.getmaxsteering()); v.updatesteering(desired_velocity.x, desired_velocity.y);
21 else { v.updatesteering(v.getvelocity());
22 Transparency.java package cargame; import java.awt.*; import java.awt.image.*; public class Transparency { public static Image makecolortransparent(image im, final Color color) { ImageFilter filter = new RGBImageFilter() { public int markerrgb = color.getrgb() 0xFF000000; public final int filterrgb(int x, int y, int rgb) { if ( ( rgb 0xFF ) == markerrgb ) { return 0x00FFFFFF & rgb; else { return rgb; ; ImageProducer ip = new FilteredImageSource(im.getSource(), filter); return Toolkit.getDefaultToolkit().createImage(ip);
public class Application extends JFrame implements ChangeListener, WindowListener, MouseListener, MouseMotionListener {
Application.java import javax.swing.*; import java.awt.geom.*; import java.awt.event.*; import javax.swing.event.*; import java.util.*; public class Application extends JFrame implements ChangeListener,
Java Mouse and Keyboard Methods
7 Java Mouse and Keyboard Methods 7.1 Introduction The previous chapters have discussed the Java programming language. This chapter investigates event-driven programs. Traditional methods of programming
Using A Frame for Output
Eventos Roteiro Frames Formatting Output Event Handling Entering Data Using Fields in a Frame Creating a Data Entry Field Using a Field Reading Data in an Event Handler Handling Multiple Button Events
core 2 Handling Mouse and Keyboard Events
core Web programming Handling Mouse and Keyboard Events 1 2001-2003 Marty Hall, Larry Brown http:// Agenda General event-handling strategy Handling events with separate listeners Handling events by implementing
Remote Method Invocation
Goal of RMI Remote Method Invocation Implement distributed objects. Have a program running on one machine invoke a method belonging to an object whose execution is performed on another machine. Remote
Chapter 2 Introduction to Java programming
Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break
INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction
INTRODUCTION TO COMPUTER PROGRAMMING Richard Pierse Class 7: Object-Oriented Programming Introduction One of the key issues in programming is the reusability of code. Suppose that you have written a program
First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
CS 335 Lecture 06 Java Programming GUI and Swing
CS 335 Lecture 06 Java Programming GUI and Swing Java: Basic GUI Components Swing component overview Event handling Inner classes and anonymous inner classes Examples and various components Layouts Panels
Image Processing. In this chapter: ImageObserver ColorModel ImageProducer ImageConsumer ImageFilter
12 In this chapter: ImageObserver ColorModel ImageProducer ImageConsumer ImageFilter Image Processing The image processing parts of Java are buried within the java.awt.image package. The package consists
file://c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html
file:c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html Seite 1 von 5 ScanCmds.java ------------------------------------------------------------------------------- ScanCmds Demontration
Construction of classes with classes
(November 13, 2014 Class hierarchies 1 ) Construction of classes with classes Classes can be built on existing classes through attributes of object types. Example: I A class PairOfDice can be constructed
Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game
Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game Directions: In mobile Applications the Control Model View model works to divide the work within an application.
The Abstract Windowing Toolkit. Java Foundation Classes. Swing. In April 1997, JavaSoft announced the Java Foundation Classes (JFC).
The Abstract Windowing Toolkit Since Java was first released, its user interface facilities have been a significant weakness The Abstract Windowing Toolkit (AWT) was part of the JDK form the beginning,
Homework/Program #5 Solutions
Homework/Program #5 Solutions Problem #1 (20 points) Using the standard Java Scanner class. Look at http://natch3z.blogspot.com/2008/11/read-text-file-using-javautilscanner.html as an exampleof using the
Advanced Network Programming Lab using Java. Angelos Stavrou
Advanced Network Programming Lab using Java Angelos Stavrou Table of Contents A simple Java Client...3 A simple Java Server...4 An advanced Java Client...5 An advanced Java Server...8 A Multi-threaded
Callbacks. Callbacks Copyright 2007 by Ken Slonneger 1
Callbacks Callbacks refer to a mechanism in which a library or utility class provides a service to clients that are unknown to it when it is defined. Suppose, for example, that a server class creates a
Event-Driven Programming
Event-Driven Programming Lecture 4 Jenny Walter Fall 2008 Simple Graphics Program import acm.graphics.*; import java.awt.*; import acm.program.*; public class Circle extends GraphicsProgram { public void
Threads 1. When writing games you need to do more than one thing at once.
Threads 1 Threads Slide 1 When writing games you need to do more than one thing at once. Threads offer a way of automatically allowing more than one thing to happen at the same time. Java has threads as
JAVA Program For Processing SMS Messages
JAVA Program For Processing SMS Messages Krishna Akkulu The paper describes the Java program implemented for the MultiModem GPRS wireless modem. The MultiModem offers standards-based quad-band GSM/GPRS
public class Craps extends JFrame implements ActionListener { final int WON = 0,LOST =1, CONTINUE = 2;
Lecture 15 The Game of "Craps" In the game of "craps" a player throws a pair of dice. If the sum on the faces of the pair of dice after the first toss is 7 or 11 the player wins; if the sum on the first
An Overview of Java. overview-1
An Overview of Java overview-1 Contents What is Java Major Java features Java virtual machine Java programming language Java class libraries (API) GUI Support in Java Networking and Threads in Java overview-2
www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk
CS506 Web Design and Development Solved Online Quiz No. 01 Which of the following is a general purpose container? JFrame Dialog JPanel JApplet Which of the following package needs to be import while handling
The following program is aiming to extract from a simple text file an analysis of the content such as:
Text Analyser Aim The following program is aiming to extract from a simple text file an analysis of the content such as: Number of printable characters Number of white spaces Number of vowels Number of
Mobile App Tutorial Animation with Custom View Class and Animated Object Bouncing and Frame Based Animation
Mobile App Tutorial Animation with Custom View Class and Animated Object Bouncing and Frame Based Animation Description of View Based Animation and Control-Model-View Design process In mobile device programming,
Orders.java. ArrayList of Drinks as they are ordered. Functions to calculate statistics on Drinks
Business and Point of Sale App Using Classes and Lists to Organize Data The Coffee App Description: This app uses a multiple class structure to create an interface where a user can select options for ordering
Twin A Design Pattern for Modeling Multiple Inheritance
Twin A Design Pattern for Modeling Multiple Inheritance Hanspeter Mössenböck University of Linz, Institute of Practical Computer Science, A-4040 Linz [email protected] Abstract. We introduce
OBJECT ORIENTED PROGRAMMING LANGUAGE
UNIT-6 (MULTI THREADING) Multi Threading: Java Language Classes The java.lang package contains the collection of base types (language types) that are always imported into any given compilation unit. This
Implementing Positioning Algorithms Using Accelerometers
Freescale Semiconductor Application Note Rev 0, 02/2007 Implementing Positioning Algorithms Using Accelerometers by: Kurt Seifert and Oscar Camacho OVERVIEW This document describes and implements a positioning
Computer Science 483/580 Concurrent Programming Midterm Exam February 23, 2009
Computer Science 483/580 Concurrent Programming Midterm Exam February 23, 2009 Your name There are 6 pages to this exam printed front and back. Please make sure that you have all the pages now. The exam
JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4
JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 NOTE: SUN ONE Studio is almost identical with NetBeans. NetBeans is open source and can be downloaded from www.netbeans.org. I
Crash Course in Java
Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is
Graphical User Interfaces
M14_REGE1813_02_SE_C14.qxd 2/10/10 3:43 PM Page 822 Chapter14 Graphical User Interfaces 14.1 GUI Basics Graphical Input and Output with Option Panes Working with Frames Buttons, Text Fields, and Labels
Principles of Software Construction: Objects, Design, and Concurrency. Course Introduction. toad. toad 15-214. Fall 2012. School of Computer Science
Principles of Software Construction: Objects, Design, and Concurrency Course Introduction Fall 2012 Charlie Garrod Christian Kästner School of Computer Science and J Aldrich 2012 W Scherlis 1 Construction
Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013
Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper
Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language
Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description
Here's the code for our first Applet which will display 'I love Java' as a message in a Web page
Create a Java Applet Those of you who purchased my latest book, Learn to Program with Java, know that in the book, we create a Java program designed to calculate grades for the English, Math and Science
Java Memory Model: Content
Java Memory Model: Content Memory Models Double Checked Locking Problem Java Memory Model: Happens Before Relation Volatile: in depth 16 March 2012 1 Java Memory Model JMM specifies guarantees given by
Java Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
JAVA - MULTITHREADING
JAVA - MULTITHREADING http://www.tutorialspoint.com/java/java_multithreading.htm Copyright tutorialspoint.com Java is amulti threaded programming language which means we can develop multi threaded program
Interactive Programs and Graphics in Java
Interactive Programs and Graphics in Java Alark Joshi Slide credits: Sami Rollins Announcements Lab 1 is due today Questions/concerns? SVN - Subversion Versioning and revision control system 1. allows
WEEK 2 DAY 14. Writing Java Applets and Java Web Start Applications
WEEK 2 DAY 14 Writing Java Applets and Java Web Start Applications The first exposure of many people to the Java programming language is in the form of applets, small and secure Java programs that run
Contents. 9-1 Copyright (c) 1999-2004 N. Afshartous
Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to
There are some important differences between an applet and a standalone Java application, including the following:
JAVA - APPLET BASICS Copyright tutorialspoint.com An applet is a Java program that runs in a Web browser. An applet can be a fully functional Java application because it has the entire Java API at its
11. Applets, normal window applications, packaging and sharing your work
11. Applets, normal window applications, packaging and sharing your work In this chapter Converting Full Screen experiments into normal window applications, Packaging and sharing applications packaging
Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.
Arrays Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html 1 Grid in Assignment 2 How do you represent the state
Intel Retail Client Manager Audience Analytics
Intel Retail Client Manager Audience Analytics By using this document, in addition to any agreements you have with Intel, you accept the terms set forth below. You may not use or facilitate the use of
Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.
Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java
Working Model 2D Exercise Problem 14.111. ME 114 Vehicle Design Dr. Jose Granda. Performed By Jeffrey H. Cho
Working Model 2D Exercise Problem 14.111 ME 114 Vehicle Design Dr. Jose Granda Performed By Jeffrey H. Cho Table of Contents Problem Statement... 1 Simulation Set-Up...2 World Settings... 2 Gravity...
Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.
Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command
Building Java Programs
Building Java Programs Chapter 4 Lecture 4-1: Scanner; if/else reading: 3.3 3.4, 4.1 Interactive Programs with Scanner reading: 3.3-3.4 1 Interactive programs We have written programs that print console
Introduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
Web Development and Core Java Lab Manual V th Semester
Web Development and Core Java Lab Manual V th Semester DEPT. OF COMPUTER SCIENCE AND ENGINEERING Prepared By: Kuldeep Yadav Assistant Professor, Department of Computer Science and Engineering, RPS College
How to Convert an Application into an Applet.
How to Convert an Application into an Applet. A java application contains a main method. An applet is a java program part of a web page and runs within a browser. I am going to show you three different
Fondamenti di Java. Introduzione alla costruzione di GUI (graphic user interface)
Fondamenti di Java Introduzione alla costruzione di GUI (graphic user interface) component - container - layout Un Container contiene [0 o +] Components Il Layout specifica come i Components sono disposti
Programming with Java GUI components
Programming with Java GUI components Java includes libraries to provide multi-platform support for Graphic User Interface objects. The multi-platform aspect of this is that you can write a program on a
LAB4 Making Classes and Objects
LAB4 Making Classes and Objects Objective The main objective of this lab is class creation, how its constructer creation, object creation and instantiation of objects. We will use the definition pane to
History OOP languages Year Language 1967 Simula-67 1983 Smalltalk
History OOP languages Intro 1 Year Language reported dates vary for some languages... design Vs delievered 1957 Fortran High level programming language 1958 Lisp 1959 Cobol 1960 Algol Structured Programming
Block IQ. Marko Boon ([email protected]) Jacques Resing ([email protected])
Block IQ Marko Boon ([email protected]) Jacques Resing ([email protected]) Part II: Object Oriented Programming 2/266 1. Objects and Classes 2. Class Inheritance and Interfaces 3. Some Predefined Java Classes
CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:
In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our
Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.
Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input
1 Hour, Closed Notes, Browser open to Java API docs is OK
CSCI 143 Exam 2 Name 1 Hour, Closed Notes, Browser open to Java API docs is OK A. Short Answer For questions 1 5 credit will only be given for a correct answer. Put each answer on the appropriate line.
Session 12 Evolving IT Architectures: From Mainframes to Client-Server to Network Computing
Session 12 Evolving IT Architectures: From Mainframes to Client- to Network Computing S. Madnick, 1998 12/ 1 Outline Stages of System Architectures Components: Data Management,, Mainframe era PC era Stages
Outline of this lecture G52CON: Concepts of Concurrency
Outline of this lecture G52CON: Concepts of Concurrency Lecture 10 Synchronisation in Java Natasha Alechina School of Computer Science [email protected] mutual exclusion in Java condition synchronisation
// Correntista. //Conta Corrente. package Banco; public class Correntista { String nome, sobrenome; int cpf;
// Correntista public class Correntista { String nome, sobrenome; int cpf; public Correntista(){ nome = "zé"; sobrenome = "Pereira"; cpf = 123456; public void setnome(string n){ nome = n; public void setsobrenome(string
Building a Multi-Threaded Web Server
Building a Multi-Threaded Web Server In this lab we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous
Java Appletek II. Applet GUI
THE INTERNET,mapped on the opposite page, is a scalefree network in that Java Appletek II. dis.'~tj port,from BYALBERTU\SZLOBARABASI ANDERICBONABEAU THE INTERNET,mapped on the opposite page, is a scalefree
Using Image J to Measure the Brightness of Stars (Written by Do H. Kim)
Using Image J to Measure the Brightness of Stars (Written by Do H. Kim) What is Image J? Image J is Java-based image processing program developed at the National Institutes of Health. Image J runs on everywhere,
Basic Object-Oriented Programming in Java
core programming Basic Object-Oriented Programming in Java 1 2001-2003 Marty Hall, Larry Brown http:// Agenda Similarities and differences between Java and C++ Object-oriented nomenclature and conventions
java.applet Reference
18 In this chapter: Introduction to the Reference Chapters Package diagrams java.applet Reference Introduction to the Reference Chapters The preceding seventeen chapters cover just about all there is to
Chapter 8 Implementing FSP Models in Java
Chapter 8 Implementing FSP Models in Java 1 8.1.1: The Carpark Model A controller is required for a carpark, which only permits cars to enter when the carpark is not full and does not permit cars to leave
Chapter 1 Java Program Design and Development
presentation slides for JAVA, JAVA, JAVA Object-Oriented Problem Solving Third Edition Ralph Morelli Ralph Walde Trinity College Hartford, CT published by Prentice Hall Java, Java, Java Object Oriented
DHBW Karlsruhe, Vorlesung Programmieren, Remote Musterlösungen
DHBW Karlsruhe, Vorlesung Programmieren, Remote Musterlösungen Aufgabe 1 RMI - TimeService public interface TimeServerInterface extends Remote { public String gettime() throws RemoteException; import java.util.date;
J a v a Quiz (Unit 3, Test 0 Practice)
Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points
How To Write A Program For The Web In Java (Java)
21 Applets and Web Programming As noted in Chapter 2, although Java is a general purpose programming language that can be used to create almost any type of computer program, much of the excitement surrounding
Week 1: Review of Java Programming Basics
Week 1: Review of Java Programming Basics Sources: Chapter 2 in Supplementary Book (Murach s Java Programming) Appendix A in Textbook (Carrano) Slide 1 Outline Objectives A simple Java Program Data-types
Extending Desktop Applications to the Web
Extending Desktop Applications to the Web Arno Puder San Francisco State University Computer Science Department 1600 Holloway Avenue San Francisco, CA 94132 [email protected] Abstract. Web applications have
public class demo1swing extends JFrame implements ActionListener{
import java.io.*; import java.net.*; import java.io.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class demo1swing extends JFrame implements ActionListener JButton demodulacion;
GUI Components: Part 2
GUI Components: Part 2 JComboBox and Using an Anonymous Inner Class for Event Handling A combo box (or drop-down list) enables the user to select one item from a list. Combo boxes are implemented with
Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 SOLUTIONS.
Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 Name: SOLUTIONS Athena* User Name: Instructions This quiz is 50 minutes long. It contains
Dashboard Skin Tutorial. For ETS2 HTML5 Mobile Dashboard v3.0.2
Dashboard Skin Tutorial For ETS2 HTML5 Mobile Dashboard v3.0.2 Dashboard engine overview Dashboard menu Skin file structure config.json Available telemetry properties dashboard.html dashboard.css Telemetry
Assignment No.3. /*-- Program for addition of two numbers using C++ --*/
Assignment No.3 /*-- Program for addition of two numbers using C++ --*/ #include class add private: int a,b,c; public: void getdata() couta; cout
Topic 11 Scanner object, conditional execution
Topic 11 Scanner object, conditional execution "There are only two kinds of programming languages: those people always [complain] about and those nobody uses." Bjarne Stroustroup, creator of C++ Copyright
Collections.sort(population); // Método de ordenamiento
import java.util.collections; import java.util.linkedlist; import java.util.random; public class GeneticAlgorithms static long BEGIN; static final boolean _DEBUG = true; LinkedList population
Interaction: Mouse and Keyboard DECO1012
Interaction: Mouse and Keyboard DECO1012 Interaction Design Interaction Design is the research and development of the ways that humans and computers interact. It includes the research and development of
Dev Articles 05/25/07 11:07:33
Java Crawling the Web with Java Contributed by McGraw Hill/Osborne 2005 06 09 Access Your PC from Anywhere Download Your Free Trial Take your office with you, wherever you go with GoToMyPC. It s the remote
Java from a C perspective. Plan
Java from a C perspective Cristian Bogdan 2D2052/ingint04 Plan Objectives and Book Packages and Classes Types and memory allocation Syntax and C-like Statements Object Orientation (minimal intro) Exceptions,
JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.
http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral
Sample CSE8A midterm Multiple Choice (circle one)
Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui
Tutorial for Tracker and Supporting Software By David Chandler
Tutorial for Tracker and Supporting Software By David Chandler I use a number of free, open source programs to do video analysis. 1. Avidemux, to exerpt the video clip, read the video properties, and save
Tutorial: Getting Started
9 Tutorial: Getting Started INFRASTRUCTURE A MAKEFILE PLAIN HELLO WORLD APERIODIC HELLO WORLD PERIODIC HELLO WORLD WATCH THOSE REAL-TIME PRIORITIES THEY ARE SERIOUS SUMMARY Getting started with a new platform
