這本書就是我們這幾次要上的很有趣的東西
相關的連結就看一下我的Blog吧:
Book : Head First Design Patterns
2004-11-20
2004-11-12
XML作業 by qazwe
1.XML文件
<?xml version="1.0" encoding="UTF-8"?>
<櫻桃小丸子>
<小丸子人物介紹>
<名字>
櫻 桃子
<成員>
小丸子本人
<年紀>
9歲
<血型>A型</血型>
</年紀>
</成員>
</名字>
</小丸子人物介紹>
<小丸子人物介紹>
<名字>
櫻 幸子
<成員>
姐姐
<年紀>
12歲
<血型>A型</血型>
</年紀>
</成員>
</名字>
</小丸子人物介紹>
<小丸子人物介紹>
<名字>
櫻桃廣志
<成員>
爸爸
<年紀>
40歲
<血型>A型</血型>
</年紀>
</成員>
</名字>
</小丸子人物介紹>
<小丸子人物介紹>
<名字>
小林瑾
<成員>
媽媽
<年紀>
40歲
<血型>A型</血型>
</年紀>
</成員>
</名字>
</小丸子人物介紹>
</櫻桃小丸子>
2.剖析結果
姓名:櫻 桃子 成員:小丸子本人 年紀:9歲 血型:A型 姓名:櫻 幸子 成員:姐姐 年紀:12歲 血型:A型 姓名:櫻桃廣志 成員:爸爸 年紀:40歲 血型:A型 姓名:小林瑾 成員:媽媽 年紀:40歲 血型:A型
2004-11-11
XML作業 by shumi
1.造出來的XML文件
<?xml version="1.0" encoding="UTF-8"?>
<Party506>
<成員>
<年級>
大四
<名字>
swanky
<星座>巨蟹</星座>
</名字>
</年級>
</成員>
<成員>
<年級>
大三
<名字>
shumi
<星座>水瓶</星座>
</名字>
</年級>
</成員>
<成員>
<年級>
大三
<名字>
qazwe
<星座>巨蟹</星座>
</名字>
</年級>
</成員>
<成員>
<年級>
大三
<名字>
queena
<星座>射手</星座>
</名字>
</年級>
</成員>
</Party506>
2.結果
大四 swanky 巨蟹 大三 shumi 水瓶 大三 qazwe 巨蟹 大三 queena 射手
2004-10-29
畫圖小程式範例 by swanky
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
public class DrawCircle extends JApplet{
boolean drawable = false;
public void init(){
super.init();
getContentPane().add(new DrawPanel(), BorderLayout.CENTER);
Action drawAction = new DrawAction();
Action cancelAction = new CancelAction();
JPanel p = new JPanel();
p.add(new JButton(drawAction));
p.add(new JButton(cancelAction));
getContentPane().add(p, BorderLayout.NORTH);
JMenu actionMenu = new JMenu("Action");
actionMenu.add(drawAction);
actionMenu.add(cancelAction);
JMenuBar menuBar = new JMenuBar();
menuBar.add(actionMenu);
setJMenuBar(menuBar);
}
public static void main(String[] args){
JApplet applet = new DrawCircle();
JFrame frame = new JFrame("DrawCircle");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet);
frame.setSize(500, 500);
applet.init();
applet.start();
frame.setVisible(true);
}
class DrawAction extends AbstractAction{
public DrawAction(){
putValue(Action.NAME, "Draw");
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl D"));
}
public void actionPerformed(ActionEvent e){
drawable = true;
}
}
class CancelAction extends AbstractAction{
public CancelAction(){
putValue(Action.NAME, "Cancel");
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl C"));
}
public void actionPerformed(ActionEvent e){
drawable = false;
}
}
class DrawPanel extends JPanel implements MouseListener, MouseMotionListener{
Point2D p1, p2;
public DrawPanel(){
addMouseListener(this);
addMouseMotionListener(this);
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
if(drawable){
if((p1 != null) | (p2 != null)){
Ellipse2D e = new Ellipse2D.Double(p1.getX(), p1.getY(),
p2.getX() - p1.getX(), p2.getY() - p1.getY());
g2d.draw(e);
}
}
}
public void mouseClicked(MouseEvent e){}
public void mousePressed(MouseEvent e){
if(drawable){
p1 = (Point2D)e.getPoint();
}
}
public void mouseReleased(MouseEvent e){
if(drawable){
p2 = (Point2D)e.getPoint();
repaint();
}
}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseDragged(MouseEvent e){}
public void mouseMoved(MouseEvent e){}
}
}
畫圓小程式 by shumi
程式碼~
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
public class DrawCircleApp extends JApplet{
boolean type = false;
public void init(){
super.init();
getContentPane().add(new DrawPanel(), BorderLayout.CENTER);
Action c = new CircleAction();
Action a = new CancleAction();
JPanel p = new JPanel();
p.add(new JButton(c));
p.add(new JButton(a));
getContentPane().add(p, BorderLayout.NORTH);
final JMenu fileMenu = new JMenu("Action");
fileMenu.add(c);
fileMenu.add(a);
final JMenuBar menuBar = new JMenuBar();
menuBar.add(fileMenu);
setJMenuBar(menuBar);
}
public static void main(String[] args){
JApplet applet = new DrawCircleApp();
JFrame frame = new JFrame("DrawCircle");
// To close the application:
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet);
frame.setSize(100, 50);
applet.init();
applet.start();
frame.setVisible(true);
}
class CircleAction extends AbstractAction{
public CircleAction(){
putValue(Action.NAME, "畫圓");
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl C"));
}
public void actionPerformed(ActionEvent e){
type = true;
}
}
class CancleAction extends AbstractAction{
public CancleAction(){
putValue(Action.NAME, "清空");
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl D"));
}
public void actionPerformed(ActionEvent e){
type = false;
}
}
class DrawPanel extends JPanel implements MouseListener, MouseMotionListener{
Point2D p1, p2;
public DrawPanel(){
addMouseListener(this);
addMouseMotionListener(this);
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
if(type){
if((p1 == null) | (p2 == null)){
return;
}
Ellipse2D e = new Ellipse2D.Double(p1.getX(), p1.getY(), p2.getX()
- p1.getX(), p2.getY() - p1.getY());
g2d.draw(e);
}
}
public void mouseClicked(MouseEvent e){}
public void mousePressed(MouseEvent e){
p1 = (Point2D)e.getPoint();
}
public void mouseReleased(MouseEvent e){
p2 = (Point2D)e.getPoint();
repaint();
}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseDragged(MouseEvent e){}
public void mouseMoved(MouseEvent e){}
}
}
Singleton範例圖(架構圖) by shumi

List1 Singleton類別
public class Singleton{
private static Singleton singleton = new Singleton();
private Singleton(){
System.out.println("已產生物件個體");
}
public static Singleton getInstance(){
return singleton;
}
}
List2 Mian類別
public class Main{
public static void main(String[] args){
System.out.println("Start.");
Singleton obj1 = Singleton.getInstance();
Singleton obj2 = Singleton.getInstance();
if(obj1 == obj2){
System.out.println("obj1和obj2是同一物件個體");
}else {
System.out.println("obj1和obj2並非同一物件個體");
}
System.out.println("End.");
}
}
Factory範例圖 by shumi

List1 Product類別
package framework;
public abstract class Product{
public abstract void use();
}
List2 Factory類別
package framework;
public abstract class Factory{
private Product lnkProduct;
public final Product create(String owner){
Product p = createProduct(owner);
registerProduct(p);
return p;
}
protected abstract Product createProduct(String owner);
protected abstract void registerProduct(Product product);
}
List3 IDCard類別
package idcard;
import framework.*;
public class IDCard extends Product{
private String owner;
IDCard(String owner){
System.out.println("建立" + owner + "的卡。");
this.owner = owner;
}
public void use(){
System.out.println("使用" + owner + "的卡。");
}
public String getOwner(){
return owner;
}
}
List4 IDCardFactory類別
package idcard;
import framework.*;
import java.util.*;
public class IDCardFactory extends Factory{
private IDCard lnkIDCard;
private Vector owners = new Vector();
protected Product createProduct(String owner){
return new IDCard(owner);
}
protected void registerProduct(Product product){
owners.add(((IDCard)product).getOwner());
}
public Vector getOwners(){
return owners;
}
}
List5 Main類別
import framework.*;
import idcard.*;
public class Main{
public static void main(String[] args){
Factory factory = new IDCardFactory();
Product card1 = factory.create("結城浩");
Product card2 = factory.create("戶村");
Product card3 = factory.create("佐藤花子");
card1.use();
card2.use();
card3.use();
}
}
Template範例圖 by shumi

List1 AbstractDisplay類別
public abstract class AbstractDisplay{
public abstract void open();
public abstract void print();
public abstract void close();
public final void display(){
open();
for(int i = 0; i < 5; i++){
print();
}
close();
}
}
List2 CharDisplay類別public class CharDisplay extends AbstractDisplay{
private char ch;
public CharDisplay(char ch){
this.ch = ch;
}
public void open(){
System.out.print("<<");
}
public void print(){
System.out.print(ch);
}
public void close(){
System.out.println(">>");
}
}
List3 StringDisplay類別public class StringDisplay extends AbstractDisplay{
private String string;
private int width;
public StringDisplay(String string){
this.string = string;
this.width = string.getBytes().length;
}
public void open(){
printLine();
}
public void print(){
System.out.println("|" + string + "|");
}
public void close(){
printLine();
}
private void printLine(){
System.out.print("+");
for(int i = 0; i < width; i++){
System.out.print("-");
}
System.out.println("+");
}
}
List4 Main類別public class Main{
public static void main(String[] args){
AbstractDisplay d1 = new CharDisplay('H');
AbstractDisplay d2 = new StringDisplay("Hello, world.");
AbstractDisplay d3 = new StringDisplay("您好。");
d1.display();
d2.display();
d3.display();
}
}
2004-10-26
2004-10-22
第二個作業
就是今天大家練習的東西
把Hello JSP Using Eclipse這個教學中的最後一個使用JSTL執行成功的JSP頁面
裡面輸入自己的名字,貼出來就可以了~
還有我已經幫大家改好標題了
以後交作業的標題後面就加上一個by 作者
Design Pattern的作業
如果是範例圖的話
要加上程式碼
記得程式碼要用<pre></pre>包起來才能固定格式喔~
2004-10-15
使用Eclipse與Sysdeo Eclipse Tomcat Launcher plugin開發簡單的JSP程式
Hello JSP Using Eclipse
這篇應該可以造福一些初學者吧~ :)
Tontie For J2ME
不知道大家知道不知道Tontie
看名字可以有點陌生
讓我們看一下底下這個link
知道了吧 就是這個好玩的Game
好玩的是 Tontie有J2ME的版本耶!!
真是太Cool了
- ScreenShot:

- Cheat:
- Press * Full health
- Press # 1000 gold
- Press Clear Go to the shop
- Press Send Next level看起來是不相當好玩的樣子呢~~
2004-10-14
Java學習資源
- JavaWorld@tw (Wiki)
台灣最大的Java論壇 - Java Technology
Sun的Java大本營,一定要常來逛逛 - java.net
Sun的Java開發者社群網站 - ONJava.com
O'Reilly的Java資訊網站 - developerWorks : Java technology (Taiwan)
IBM的Java資訊網站 - Cafe au Lait Java News and Resources
Elliotte Rusty Harold的網站,有許多新聞與資料,還有一些電子書 - Bruce Eckel's MindView, Inc.
Thinking in Java作者:Bruce Eckel的網站,可以在這裡抓他的電子書
Adapter(委讓)範例圖 by shumi
Adapter Pattern-2 委讓
程式碼
List 2-1 Banner 類別
public class Banner{
private String string;
public Banner(String string){
this.string = string;
}
public void showWithParen(){
System.out.println("(" + string + ")");
}
public void showWithAster(){
System.out.println("*" + string + "*");
}
}
List 2-2 Print類別
public abstract class Print{
public abstract void printWeak();
public abstract void printStrong();
}
List 2-3 PrintBanner類別
public class PrintBanner extends Print{
private Banner banner;
public PrintBanner(String string){
this.banner = new Banner(string);
}
public void printWeak(){
banner.showWithParen();
}
public void printStrong(){
banner.showWithAster();
}
}
List 2-4 Main類別
public class Main{
private Print lnkPrint;
public static void main(String[] args){
Print p = new PrintBanner("Hello");
p.printWeak();
p.printStrong();
}
}
Adapter(繼承)範例圖 by shumi
Adapter Pattern-1繼承
程式碼
List 2-1 Banner類別
public class Banner{
private String string;
public Banner(String string){
this.string = string;
}
public void showWithParen(){
System.out.println("(" + string + ")");
}
public void showWithAster(){
System.out.println("*" + string + "*");
}
}
List 2-2 Print介面
public interface Print{
public abstract void printWeak();
public abstract void printStrong();
}
List 2-3 PrintBanner類別
public class PrintBanner extends Banner implements Print{
public PrintBanner(String string){
super(string);
}
public void printWeak(){
showWithParen();
}
public void printStrong(){
showWithAster();
}
}
List 2-4 Main類別
public class Main{
/**
* @stereotype Uses
*/
private Print lnkPrint;
public static void main(String[] args){
Print p = new PrintBanner("Hello");
p.printWeak();
p.printStrong();
}
}
2004-10-11
PO文範本
由於預設的自動換行格式會很奇怪地加上許多換行的<br />標籤
造成版面不好控制
所以之後大家就直接用標準的XHTML語法來po文章吧
最簡單的方式就是在每一行後面,加上換行的<br />標籤
我也幫大家準備了一個範本
大家po完文章記得把這些文字弄掉喔~ :)
<!-- 範本
段落:<p></p>
換行:<br />
固定格式:<pre></pre>
超連結:<a href=""></a>
加強:<em></em>
強調:<strong></strong>
有序列表:
<ol>
<li></li>
</ol>
無序列表:
<ul>
<li></li>
</ul>
表格:
<table border="1">
<tr>
<th scope="col"> </th>
<th scope="col"> </th>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
</tr>
</table>
-->
Party這三週的作業
先畫出各Pattern的UML圖,再把程式補上
要po出UML圖、程式、還有Pattern的UML架構圖
UML圖要加上名字喔~
| 10/8~14 | 10/15~21 | 10/22~28 | |
|---|---|---|---|
| shumi |
|
|
|
| qazwe |
|
|
|
| queena |
|
|
|
2004-10-10
Iterator範例圖 by shumi
List 1-1 Aggregate 介面
public interface Aggregate {
public abstract Iterator iterator();
}
List 1-2 Iterator 介面
public interface Iterator {
public abstract boolean hasNext();
public abstract Object next();
}
List 1-3 Book 類別
public class Book {
private String name ="";
public Book(String name){
this.name = name;
}
public String getName(){
return name;
}
}
List 1-4 BookShelf類別
public class BookShelf implements Aggregate{
private Book[] books;
private int last = 0;
public BookShelf(int maxsize){
this.books = new Book[maxsize];
}
public Book getBookAt(int index){
return books[index];
}
public void appeandBook(Book book){
this.books[last] = book;
last++;
}
public int getLength(){
return last;
}
public Iterator iterator(){
return new BookShelfIterator(this);
}
}
List 1-5 BookShelfIterator類別
public class BookShelfIterator implements Iterator{
private BookShelf bookShelf;
private int index;
public BookShelfIterator(BookShelf bookShelf){
this.bookShelf = bookShelf;
this.index = 0;
}
public boolean hasNext(){
if(index < bookShelf.getLength()){
return true;
}else{
return false;
}
}
public Object next(){
Book book = bookShelf.getBookAt(index);
index++;
return book;
}
}
List 1-6 Main類別
public class Mian {
public static void main(String[] args) {
BookShelf bookShelf = new BookShelf(4);
bookShelf.appeandBook(new Book("Around the World"));
bookShelf.appeandBook(new Book("Bible"));
bookShelf.appeandBook(new Book("Cinderrella"));
bookShelf.appeandBook(new Book("Daddy-Long-Legs"));
Iterator it = bookShelf.iterator();
while(it.hasNext()){
Book book = (Book)it.next();
System.out.println("" + book.getName());
}
}
}
2004-10-08
FRIDAY Party 作業1
練習畫UML圖
這個程式是把書籍(Book)放到書架(BookShelf)上,並依序輸出書名。
List 1-1 Aggregate 介面
--
加油囉~
這個程式是把書籍(Book)放到書架(BookShelf)上,並依序輸出書名。
List 1-1 Aggregate 介面
public interface Aggregate {
public abstract Iterator iterator();
}
List 1-2 Iterator 介面
public interface Iterator {
public abstract boolean hasNext();
public abstract Object next();
}
List 1-3 Book 類別
public class Book {
private String name ="";
public Book(String name){
this.name = name;
}
public String getName(){
return name;
}
}
List 1-4 BookShelf類別
public class BookShelf implements Aggregate{
private Book[] books;
private int last = 0;
public BookShelf(int maxsize){
this.books = new Book[maxsize];
}
public Book getBookAt(int index){
return books[index];
}
public void appeandBook(Book book){
this.books[last] = book;
last++;
}
public int getLength(){
return last;
}
public Iterator iterator(){
return new BookShelfIterator(this);
}
}
List 1-5 BookShelfIterator類別
public class BookShelfIterator implements Iterator{
private BookShelf bookShelf;
private int index;
public BookShelfIterator(BookShelf bookShelf){
this.bookShelf = bookShelf;
this.index = 0;
}
public boolean hasNext(){
if(index < bookShelf.getLength()){
return true;
}else{
return false;
}
}
public Object next(){
Book book = bookShelf.getBookAt(index);
index++;
return book;
}
}
List 1-6 Main類別
public class Mian {
public static void main(String[] args) {
BookShelf bookShelf = new BookShelf(4);
bookShelf.appeandBook(new Book("Around the World"));
bookShelf.appeandBook(new Book("Bible"));
bookShelf.appeandBook(new Book("Cinderrella"));
bookShelf.appeandBook(new Book("Daddy-Long-Legs"));
Iterator it = bookShelf.iterator();
while(it.hasNext()){
Book book = (Book)it.next();
System.out.println("" + book.getName());
}
}
}
--
加油囉~
2004-10-07
2004-10-06
超好用工具
下面是我目前推薦大家寫Java程式使用的工具
- Java IDE:Eclipse(3.0.1)
- UML Design Tool:Together Community Edition for Eclipse(6.3)
- GUI Builder:Jigloo SWT/Swing GUI Builder for Eclipse and WebSphere (3.0.1)
學會它們,你寫程式起來會很Happy
不會它們,你寫程式起來就不會那麼Happy
大家要瞭解這個重要性啊~
有關Eclipse的教學
可以看看我Blog裡面的內容
也可以看看JavaWorld@tw的相關討論喔~
大家加油吧~ :)
506研究室開Party囉~
Party in 506
這是506研究室的Blog
也是研究室成員討論、研究、聊天、打屁、八卦的所在
感覺上是很容易乾旱的地方...
所以希望大家多多分享自己的研究成果囉 :)
另外
我是數資94級的蕭宇程
請多指教~
訂閱:
意見 (Atom)





