|
Site Index
About Me
Welcome
Definition of Program
Variable Types
Understanding Memory
Declaring Variables
Simple Commands
Concatenation and Strings
Sleep-Threads-Try
Catch
Campus Scenes
Pictures
Java simplified
Application Shell Styles
Reading Data From
File
Overview of Applets
Excellent Graphics
Applet
Online Reference
Nested
if statements
Arrays
Sorting Arrays
Using Strings
Functions
Top
20 Replies
First program 211
Important Class Example
JAVA in SDK Environment
Understanding
OOP
OOP simple example
Recursion example
Example of Inheritance
and use of JTextArea
*** Web Related **********
Build Student Web Page
?
What
is FTP
Download
WS ftp95
Download
Java Plug In
Applets
from jbuilder to sdk
Practice Problems

Programming Examples
| |
Sleep Threads and Try Catch
// catching exceptions is an important part of good
// software design. Handle a problem if it occurs
// so that your program can keep running
// Threads are important in I/O -- we will doscuss later
// but below is how to create a pause for so many milliseconds
// In English try to pause for 100 milliseconds and if you can
// not then catch the exception and do something else (etc )
Thread t1 = new Thread();
......
......
try { t1.sleep(100); }
catch(Exception e )
{ etc }
--------------------------------------------------------------
// an easier example to see
try
{
avg = tot / num // assume num is zero
}
catch (ArithmeticException e)
{
do something here to deal with the error
}
--------------------------------------------------------------
// multiple branching branch if 1 or 2 or neither
// this can replace a series of if statements
switch(number)
{
case 1: ........
break;
case 2: ......
break;
default: ......
break;
}
-------------------------------------------------------------
// different variation on a for loop
for (i=1, j=1, k=1; K < 100; k++,i++,j++)
{
...
}
------------------------------------------------------------
|
|