Showing posts with label Java lessons. Show all posts
Showing posts with label Java lessons. Show all posts

Wednesday, March 7, 2012

Tools for Java Lessons

Pete was complaining that teaching his friends Java through screen sharing was not very efficient, since you can share your screen to one other person at a time.  He also said that video chatting using Skype can only work with one other person, too.  If you want to have video conference with more than one party, you have to pay for it.  I certainly am not ready to pay to teach lessons, yet.

After having thought about the efficient ways to deliver the lessons, I realized that we can use Google+ hangout for multi-party video conferences.  And video from screen capture should be a clear way to deliver a programming tutorial.  I have seen many tutorials from Youtube, but have never done it myself.  I went searching and found Ksnapshot for Linux among other apps, and several other free apps for windows.  I tried out Ksnapshot and really liked it.  Pete will find a Windows app he likes.

So, with a blog for the text part of material, a screen video capture tool for video tutorials, and Google+ hangout for video conferences, we are all set for the exciting Java programming lessons to come, I think.

Monday, March 5, 2012

Additional Info for 2nd Lesson

The following should be added to class Point.  The test function should become the tradition for every class to be coded in the future.


   void drawCross(Graphics g){
int sz = 3;
g.drawLine(x-sz, y, x+sz, y);
g.drawLine(x, y-sz, x, y+sz);
   }


   static void  test0(String path){
BufferedImage img = new BufferedImage(100,80,BufferedImage.TYPE_INT_RGB);
Point p1 = new Point(10,10);
Point p2 = new Point(20,30);
Graphics g = img.getGraphics();
g.setColor(Color.gray );
g.fillRect ( 0, 0, img.getWidth(), img.getHeight() );
g.setColor(Color.red );
p1.drawCross(g);
p2.drawCross(g);
try {
ImageIO.write(img, "PNG", new File(path));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
   }

Sunday, March 4, 2012

Simpler 2nd Lesson?

Maybe the 2nd lesson I suggested was a little too ambitious.  So I decided put the following task before that:

class Point{
    int x, y;
    Point(){...}                                // default constructor
    Point(int x, int y){...}                // another constructor
    Point(Point p){...}                     // copy constructor
    float getDistance(Point p){...}
    void draw(Graphics g){..}        //draw a cross, or a circle?

}

class Line{
    Point p1, p2;

    Line(int x1, int y1, int x2, int y2){...}
    float getLength(){...}
    void draw(Graphics g) {...}

}


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.