這本書就是我們這幾次要上的很有趣的東西
相關的連結就看一下我的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.");
}
}
訂閱:
意見 (Atom)
