Gui Guan’s BLOG

There’s more than one way to do it

Archive for August, 2007

Java simulation for Brownian motion

RacingParticles

Here is the Java program written by me to simulate the Brownian motion. In this prac, I tried to use double buffering to improve the performances, but actually it is triple buffering. That’s because the JPane has already implemented the double buffering, so plus mine own copy of buffer to store the background coordinate system and the path of particles, it is triple! Ho ho :P

  • 0 Comments
  • Filed under: Java, Life
  • repaint(), paint() and update()

    Many Java programmers are befuddled by the three methods repaint(), paint(Graphics), and update(Graphics). This is because they are designed to work in a wide variety of circumstances, and they interact in a non-obvious fashion. This happens in several contexts in Java, but GUIs are the most obvious. The designers of Java wanted Java programs to be able to run on any machine that had a Java VM. So, a particular program might be running on a desktop machine, or a laptop, or a hand-held machine, like a personal assistant or a phone. This presents quite a challenge for the designer of an abstract windows toolkit (AWT). It also makes the job of a novice programmer more difficult than it might otherwise be. So it goes.

    i) public void update(Graphics)
    By default update(Graphics) fills the drawable area of a Component with its background color, and then sends paint(Graphics) to the object. Thus, flicker that comes from redrawing the background over and over, can sometimes be fixed by overriding update() (see Code Example 9 on page 238, Simple Java).

    ii) public void paint(Graphics)
    Every Java Component implements paint(Graphics), which is responsible for painting that component in the Graphics context passed in the parameter. When you extend a Component (like when you write a Applet), if you want to display it differently than its superclass, you override public void paint(Graphics) . This was first illustrated in Chapter 3, Simple Java. (more…)

  • 0 Comments
  • Filed under: Java
  • Gui Guan’s Laboratory

    Gui Guan’s Laboratory
    There’s more than one way to do it

    Gui Guan's Laboratory Logo

    http://lab.guiguan.net

    发现Bluehost的服务器环境非常适合在学校和家里来测试PHP脚本,呵呵。同时为了更好的学习Internet Computing,弄了一个自己的实验室,有点Google’s Lab的感觉,但是差远老:P lol

    当你点击进入之后,便是我完成的IC的第二次作业啦(默认用户名:user 密码:password)。以下是这次作业的一些要点:

    • sticky form
    • input validation
    • POST
    • SESSION
    • mail

    (待续…)

  • 0 Comments
  • Filed under: Life, PHP, Website Log
  • FAQ about Java import

    1. Q: Does importing all classes in a package make my object file (.class or .jar) larger?

    A: No, import only tells the compiler where to look for symbols.

    2. Q: Is it less efficient to import all classes than only the classes I need?

    A: No. The search for names is very efficient so there is no effective difference.

    3. Q: Doesn’t it provide better documentation to import each class explicitly? (more…)

  • 2 Comments
  • Filed under: Java
  • Last week, during the prac 2 of CS IB, we were asked to program in Java to build a simple client/server system in which the server takes “commands” from the client and executes them. Due to the time restriction, we were only asked to implement the server, and use telnet to act as client to transact with server. You can have a look here for details.

    1
    2
    3
    4
    5
    
    ServerSocket server = new ServerSocket(6666);
    Socket s= server.accept();
    // We now have a client on the end of the socket s
    BufferedReader in = new BufferedReader( new InputStreamReader( s.getInputStream()));
    PrintWriter out = new PrintWriter(s.getOutputStream());

    It’s no more than the knowledge above. Maybe the simplest nextwork program in Java world.

    The telnet on lab’s Mac just work well, but after I brought my program to home and run on my own computer, I met a really troublesome problem with the Microsoft’s telnet in Windows XP.

    1. First, I started my server.

    telnet_1.png (more…)

    Arenal Volcano Costa Rica

    I found this in Google Earth today. It’s so beautiful! After I showed this to Pat, he replied immediately “i want to build my house there”. Indeed, that’s also my dream. Great pic, thx Roberto Garcia.

    Arenal Volcano Costa Rica

    The Arenal Volcano is the only volcano in Costa Rica constantly active since it woke up after 400 years with the big 1968 eruption producing huge ash columns, explosions & glowing red lava almost every day. It is considered one of the ten most active volcanoes in the world. This country is about beaches, rainforest and the spectacular Arenal.

  • 20 Comments
  • Filed under: Life
  • Plan for sem 2 2007

    虽然每天都睡得很晚,但还是感觉时间不够用。在计算机科学浩瀚的海洋中,奋斗一个问题,花上我5-6个小时是很正常的事情。因此常常在想,到底是做事的效率太低,还是太高?第二学期开始已经两周了,Java已经把stream和网络讲完了,下周就要开始讲图形界面了;数学刚把微分方程讲完;网络编程刚进入PHP阶段;MIT的笔记刚抄到概率问题…但我还是稀里糊涂,像刚睡醒一样。原定计划,Perl应该在这周看完了,但是现在还只完成1/3不到,而且借的书已经被图书馆催着还回去了。看来还是效率太低了,导致时间的利用率一直保持在原始阶段。还记得上次跟Thin聊天,谈到他是如何学习计算机的,他说他的那些知识都是靠自学,上课的时候都是睡大觉(估计晚上熬夜了),然后毕业照片上终于睡醒了。其实,到目前为止,我的计算机知识99%都是靠自学的。那些最前沿的技术,你是不能够等着老师来教你的,老师教给你的只能是一些基础知识。所以Thin的做法何况不是我的做法呢?不过现在头疼的就是效率问题了。分析了前面一大段废话之后,拟定了以下计划,称之为Plan for sem 2 2007

    1. 为ACM ICPC做准备
      1. 参加学校的ICPC培训
      2. 继续阅读The art of Computer Programming (估计以后Gui Guan’s BLOG关注算法的问题会比较多了)
      3. Top-coder
      4. 积极参与讨论
      5. 减少游戏时间
    2. 完成Perl
    3. 精通PHP
    4. 初步了解AI
    5. 找一份part time job, 参加社会实践
    6. 获取驾照
    7. ?

    以上列表更新于2007-8-26

  • 13 Comments
  • Filed under: Life, Website Log