Let's go inside

missionstart@126.com
posts - 58, comments - 0, trackbacks - 0, articles - 0

置顶随笔

     摘要: ~  阅读全文

posted @ 2006-08-24 15:45 Earth| 编辑 收藏

2007年1月7日

给一个陌生人做的作业,

要求如下:
编写一个TCP Socket程序,采用图形化的界面实现,在服务器可输入客户端的IP地址和端口号,程序根据该IP地址和端口号与客户端建立连接,在服务器端输入要发送的内容点击发送按钮,就可以发送到客户端,客户端只接收服务器端发送的消息。

正好在学SWT, 就一边学一边写了,可以到这里去下载源代码http://www.eclipseworld.org/bbs/read.php?tid=10290

凭记忆总结一下期间碰到的问题,一个是如果button要处理一个可能会阻塞或耗时的事件,那个事件处理的需要放在一个新的Thread里边。不然的话。界面没法响应其它的操作。

另外如果要在新的线程里操作SWT中的元素比如文本框。必须像下面这样处理。
 display.asyncExec(new Runnable() {
  public void run() {
   listenButton.setEnabled(false);
  }
 });
否则会抛出好像是什么invalid access的异常。

最后在进行Socket编程的时候要把防火墙关掉。否则会抛出JVM_bind之类等莫名其妙的错误

哈哈,今天又发现了一个问题。。就是改成keyReleased() 以后。。还是要按照那个回贴的人来做。String text = sendText.getText().trim() + lineS;

因为如果发送的消息末尾没有line.separator的话。。在客户端

       BufferedReader in = new BufferedReader(
         new InputStreamReader(socket
           .getInputStream()));
       while (true) {
        String str;
        while ((str = in.readLine()) != null) {
         append(lineS + str);
        }
        Thread.sleep(500);
       }
就收不到?。消息的末端必须要有断行符!呵呵。这样in.readLine()才算读到行尾才会打出来 。可以做一个试验。输入a,点按钮,client没反应,再输入b,点按钮,client没反应,再输入c, 这次用Ctrl + Enter发送。这样client一次打印出abc来。。呵呵 。!!明白了 !!!!!

posted @ 2007-01-07 21:19 Earth| 编辑 收藏

2006年11月26日

转自:http://bobcat.webappcabaret.net/javachina/jc/ptn/Visitor.htm

VisitorPattern.java


posted @ 2006-11-26 22:37 Earth| 编辑 收藏

2006年11月15日

     摘要:   阅读全文

posted @ 2006-11-15 09:29 Earth| 编辑 收藏

2006年11月10日

每次插上移动硬盘,windows都要扫描好半天,关起来也很麻烦,
要关闭自动播放的功能,操作如下:
Fn+R,     输入gpedit.msc,回车 
然后依次点击 计算机配置-〉管理模版-〉系统-〉关闭自动播放

posted @ 2006-11-10 09:13 Earth| 编辑 收藏

2006年10月25日

     摘要:   阅读全文

posted @ 2006-10-25 22:46 Earth| 编辑 收藏

好久不博,恢复中~~
主要原因好久不弄JAVA,
今天晚上回来。把IBM SDK 1.4.2, ECLIPSE3.1.2装好后, 又下了swt designer5.0及破解文件
一番辛苦,把hello world 弄出来咯~~

其中有一个叫swt-win32-3139.dll的SWT原生包文件在D:\eclipse\configuration\org.eclipse.osgi\bundles\14\1\.cp下面。需要拷贝到C:
WINDOWS\system32下面

嗯。下一篇是关于hello world jdom的。等我弄好了再博一篇

posted @ 2006-10-25 22:06 Earth| 编辑 收藏

2006年10月23日

The first good news:
Sky win the WCG2006 champion, follow this link and leave a message there:
sky's sina blog

The second good news:
I received 5 ubuntu CDs today from receptionist due to my subscription one month ago from Ubuntu Official Website, tho it's 6.06 LTS, it's terrific news for me! i m very excited about that~

posted @ 2006-10-23 21:19 Earth| 编辑 收藏

2006年10月8日

     摘要:   阅读全文

posted @ 2006-10-08 10:00 Earth| 编辑 收藏

2006年9月23日

     摘要: 北京的冬季,地上还有积雪,灰黑色的秃树枝丫叉于晴朗的天空中,而远处有

一二风筝浮动,在我是一种惊异和悲哀。  阅读全文

posted @ 2006-09-23 21:41 Earth| 编辑 收藏

2006年9月15日

     摘要: ~  阅读全文

posted @ 2006-09-15 21:23 Earth| 编辑 收藏