Presentation is loading. Please wait.

Presentation is loading. Please wait.

Handling Errors in Java Programming. // The “name-of-application” class import java.awt.*; import hsa.Console; public class name-of-application { static.

Similar presentations


Presentation on theme: "Handling Errors in Java Programming. // The “name-of-application” class import java.awt.*; import hsa.Console; public class name-of-application { static."— Presentation transcript:

1 Handling Errors in Java Programming

2 // The “name-of-application” class import java.awt.*; import hsa.Console; public class name-of-application { static Console c; static public void main (String [] args) { c = new Console (); your program goes here } // main method any user-defined methods go here } // name-of-application class

3 // The “GreenOval” class import java.awt.*; import hsa.Console; public class GreenOval { static Console c; static public void main (String [] args) { c = new Console (); c.setColor (Color.green); c.fillOval (0, 0, 100, 200); } // main method } // GreenOval class

4 // The “GreenOval” class import java.awt.*; import hsa.Console; public class GreenOval { static Console c; static public void main (String [] args) { c = new Console (); c.setColor (Color.green); c.fillOval (0, 0, 100, 200); } // main method } // GreenOval class delete the semicolon

5

6 // The “GreenOval” class import java.awt.*; import hsa.Console; public class GreenOval { static Console c; static public void main (String [] args) { c = new Console (); c.setColor (Color.green); c.fillOval (0, 0, 100, 200); } // main method } // GreenOval class delete c.

7

8 // The “GreenOval” class import java.awt.*; import hsa.Console; public class GreenOval { static Console c; static public void main (String [] args) { c = new Console (); c.setColor (Color.green); c.fillOval (0, 0, 100, 200); } // main method } // GreenOval class delete the close curly brace

9

10 // The “GreenOval” class import java.awt.*; import hsa.Console; public class GreenOval { static Console c; static public void main (String [] args) { c = new Console (); c.setColor (Color.green); c.fillOval (0, 0, 100, 200); } // main method } // GreenOval class uppercase the c

11

12 Multiple errors

13 There are actually 4 errors

14 lowercase c missing semicolon c. is missing main mispelled

15 Debugging Activity Before your program is compiling and running correctly Put in 2 simple errors Compile Swap seats with a classmate Debug each other’s “buggy” programs

16 Face Write a program that produces a picture of a face. It must consist of at least 4 different colors and the following: head, eyes, nose, mouth. Name this class Face. graphics in java.awt.* … drawLine void drawLine (int x1, int y1, int x2, int y2) drawOval void drawOval (int x, int y, int width, int height) … graphics in hsa.console.* clearRect void clearRect (int x, int y, int width, int height) … drawArc void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle)

17 drawLine (int x1, int y1, int x2, int y2); fillOval (int x, int y, int width, int height); (x,y)  -------------------width------------------------  Height

18 Start a new hsa console app and call it Face }//main method static public void circle(int xc, int yc, int radius, Color clr) { int width = radius * 2; int height = radius * 2; int x = xc - radius; int y = yc - radius; c.setColor(clr); c.drawOval(x,y,width,height); }//circle method

19 public static void main (String[] args) { c = new Console (); int xc = c.getWidth() /2; int yc = c.getHeight() /2; int radius = c.getHeight() /2; circle(xc, yc, radius, Color.red);

20 c.setColor(Color.black); c.drawLine(250,300,400,300);

21 int xe = c.getWidth() /3; int ye = c.getHeight() /4; int e_rad = c.getHeight() /50; circle(xe, ye, e_rad, Color.blue);

22 int ae = xc + (xe / 2); int be = c.getHeight() /4; int a_rad = c.getHeight() / 50; circle(ae, be, a_rad, Color.orange); int ayn = c.maxy () / 2; int axn = c.maxx () / 2; int rad = 16; circle(axn, ayn, rad, Color.green); } // main method


Download ppt "Handling Errors in Java Programming. // The “name-of-application” class import java.awt.*; import hsa.Console; public class name-of-application { static."

Similar presentations


Ads by Google