Download presentation
Presentation is loading. Please wait.
1
Systems of Computation
CSC 171 FALL 2001 LECTURE 4
2
History The First Programmer
Ada Augusta King, Countess of Lovelace translates Menabrea's pamphlet on the Analytical Engine, adding her own notes the world's first programmer
3
A Whole System Interface Implementation of interface Program
4
Interface // TempConverter.java // Compiled to TempConverter.class
public interface TempConverter { public double F2C(double f); public double C2F(double c); }
5
Implementation // MyConverter.java -> MyConverter.class
public class MyConverter implements TempConverter { double currenttemp; public double F2C(double f) {return f*2 ;} public double C2F(double c){return c/2 ;} public double F2K(double f){return f ;} }
6
Program public class testConverter {
public static void main(String[] args){ MyConverter m1 = new MyConverter(); double t1 = 90; double t2 = m1.F2C(t1); System.out.println(t1 + " F == " + t2 + " C "); }
7
Applets Applications demonstrate event driven programming
We think of programs as “sequences” Begin at the beginning Continue to end Then stop But some computation “waits around to respond to the environment”
8
The lives of an applet public void init() public void start()
public void paint(Graphics g) public void stop() public void destroy()
9
public void init() Called only once Called when applet is loaded
Performs initialization Instance variables GUI components Loading media Creation of threads
10
public void start() Called after init() completes
Called every time th browser returns to the HTML page where the applet lives Controls media Starts animations Starts threads
11
public void paint(Graphics g)
Called after init() completes and start() begins Draws on the applet On the Graphics object “g” Graphics object “g” is autopassed to paint() Called when applet is repainted Window refresh
12
public void stop() Normally called when user leaves HTML page
Stops (suspends) animations and threads Saves processing power
13
public void destroy() Called when the applet is removed from memory
When the browser exits Releases allocated resorces
14
Decimal format Consider Output “t3 == 0.3333333333333333”
double t3 = 1.0/3.0; System.out.println(“t3 == “ + t3); Output “t3 == ”
15
Decimal format import java.text.DecimalFormat; DecimalFormat twoDig =
new DecimalFormat(“0.00”);
16
Decimal Format Output “t3 == 0.33” double t3 = 1.0/3.0;
String s1 = twoDig.format(t3); System.out.println(“t3 == “ + s1); Output “t3 == 0.33”
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.