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){}
    }

Thursday, February 23, 2012

A Java Programming Class for High School Students

Pete has been learning programming for several years now.  Recently, he spends a lot of time playing online video games with his friends.  I suggested that they might as well be productive and learn to program.  Specifically, learn to program in Java, and make the iRobot Create we bought a while ago do something interesting.  Two of Pete's friends decided they will do it.

My favorite IDE (Integrated Development Environment) is Netbeans, and this is what they are going to install one their own laptops. And of course, the right Java SDK.  We'll see how it's going.  Hopefully, they are going to hang on, and the group will grow a little bigger, say, 8-10 students.

I have decide the final format, yet.  To start with, Pete will show them how to install IDE and Java SDK, and simple Hello-World program.  And then do the some drawing, such as line, rectangl, oval, text.  I will get them over to our living room, and I will give a simple class explaining image, and it's manipulation.  I am eager to find our how it goes.