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();
}
}
Monday, March 5, 2012
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) {...}
}
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){}
}
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.
Wednesday, August 17, 2011
Grace's Internship at Buck Institute
This summer, Grace got a valuable opportunity to work as an intern at the Buck Institute (http://www.buckinstitute.org) for 6 weeks along with 13 other high school students, and actually received stipend at the end. The Buck Institute is a non-profit research institute on aging process. Her work involved mitochondria, the energy producing component in a cell. Under a post-doc's supervision, Grace learned to do some simple lab experiments, and related calculations.
Grace's work investigates the effect of membrane potential on ROS (reactive oxygen species, also known as free radicals). The figure below says that electrons generated by succinate oxidation may travel in reverse through complex I and result in high rates of ROS production, and the process could result in high membrane potential. FCCP uncouples mitochondrial membrane potential.

During this time, one of our favorite dinner table topics was her day's work at the institute. The whole family learned a few things regarding cell biology along with her. At the end of the internship, Grace gave a Powerpoint presentation to her lab, and the whole family.
All of the students are required to give a poster presentation at end. The family and friends were invited to the occasion. Having been to many scientific conferences, I was very much impressed by all the posters. All of them are very focused. I had the opportunity to listen to many the the presenters, and was impressed by their understanding of the material. The director of the institute made an effort to walk around the posters and picked three to present at the next day's scientific board meeting. Grace's poster won the first prize among the three. She was invited for lunch and presentation next day. It was such a valueble experience for her.
Tuesday, August 16, 2011
Vacation in Disneyland
Vacation can be exhausting. Last weekend, our family (Dongfen, Huiying, Grace, Pete, and Mark) spent two days in Disneyland and California Adventure Park. Besides having rides, we also went shopping. Mark even went to Build-A-Bear and got stuffed dog, which he named Buddy. Kids certainly had a lot of fun, although very tiring. But for Dongfen and Huiying, much more tiring than fun. We were at Disneyland several year ago before we had Mark. Hopefully, this was our last trip to Disneyland. We have more interesting places in mind for our future vacations.
Subscribe to:
Posts (Atom)