Sunday, February 26, 2012

First Two Java Lessons

The first Java lesson was as follows, under Netbeans:

1.  create a Java project.
2.  in the project, create a class that extends JFrame.
3.  in the JFrame class, add public void paint(Graphics g){...}
4.  in the paint() function,
     a) draw a rectangle,
     b) fill a oval,
     c) draw a text string

I delegated the task to Pete, and it went very smoothly.  They were able to share screens when they communicate.  According to Pete, they all were very excited during the process.  They were able to add a few lines of code and see different ovals of different sizes and colors showing up in the own screens.  This is much exciting than printing text results on the computer console.

Next lesson:  learn the concepts of class, its member data, member functions;  Learn some object orientated comcepts: class reuse through inheritance and composition; member function overloading and overriding.

Task: creating and finishing following classes:
1.
    class Point{
        int x, y;
        public Point(){}
        public Point(int x, int y){}
        public void draw(Graphics g){}
    }

2.
    class Rectangle{
        protected int left, right, top, bottom;
        .......
        public Rectangle(int x1, int y2, int x2, int y2){...}
        public void draw(Graphics g){}
    }

3.
    class Oval extends Rectangle{
        .......
        public void draw(Graphics g){}
    }

4.
    class Polygon{
        ArrayList<Point> vPnt;
        .......
        public void draw(Graphics g){}
        public void addPoint(int x, int y){}
    }

No comments:

Post a Comment