คำถามคาใจ:
ในคลาสลูก การเรียก Constructor super() ของคลาสพ่อแบบ explicit กับการไม่เรียก
ให้ผลต่างกันอย่างไร?
การใช้ this กับไม่ใช้ this นั้นมีผลต่อ inheritance อย่างไร คือพอถูก subclass ไปแล้ว this ที่ในคลาสพ่อก็ยังคง refer ถึงตัวคลาสพ่ออยู่ดีใช่ป่าว?
ทั้งหมดนี้น่าจะหาำคำตอบได้ใน Java Specification Book ไว้ว่างๆ ไปเช็คแล้วจะกลับมาตอบ
วันศุกร์, ธันวาคม 09, 2548
วันพฤหัสบดี, ธันวาคม 01, 2548
Java : Windows Font Look And Feel
สำหรับ application ที่เจาะจงว่าจะรันบนวินโด้ โดยเฉพาะนั้น เพื่อให้รูปแบบของฟอนต์สอดคล้องกับของวินโด้แต่ดั้งเดิม ควรเลือกใช้ Tahoma ขนาดตั้งแต่ 12 - 15
Java : เกี่ยวกับเรื่องของ ชิ้นส่วนภาชนะ Container Components
ใน Swing นั้น, เรามี Top-level Container อยู่คือ JFrame, JDialog และ JApplet.
สิ่งที่ควรสำเหนียก เวลาใช้พวก class เหล่านี้คือ
ตัวอย่างของ containment hierarchy ลำดับชั้นของภาชนะ
Features ของ JComponent ที่น่านำไปใช้ในโปรแกรม
การใช้ Text Components
อ้างอิง
จาวา ติวโตเรี่ยล
สิ่งที่ควรสำเหนียก เวลาใช้พวก class เหล่านี้คือ
- ทุก component ที่จะปรากฏบนจอ จะต้องอยู่ใน containment hierarchy---เป็นต้นไม้ของ component ซึ่งมี top-level container เป็นราก
- ทุก GUI component ถูกยัดใส่ลงภาชนะ ได้แค่ครั้งเดียว. ถ้าเราเอา component ไหนยัดลงไปใน container หนึ่งแล้ว และจับมันยัดลงไปใน container อื่นอีก, ก็หมายความว่า มันต้องถูกเอาออกมาจาก container แรกก่อนจึงถูกนำไปยัดใส่ container ที่สองได้
- ทุก top-level container มี content pane ซึ่งกล่าวอย่างคร่าวๆได้ว่า content pane นั้น บรรจุ visible components ใน GUI ของ top-level container ทั้งโดยตรงและโดยอ้อม.
- เราสามารถเลือกที่จะใส่ menu bar ไปที่ top-level container หรือไม่ก็ได้. ซึ่ง menu bar นั้นจะถูกวางอยู่ภายใน top-level container, แต่อยู่นอก content pane. ในบาง look and feels, เช่น Mac OS look and feel, มีทางเลือกให้เราวางตำแหน่งของ menu bar ที่อื่นซึ่งเหมาะสมกว่าได้, เช่นที่ส่วนบนสุดของหน้าจอ เป็นต้น. ดังภาพข้างล่าง
ตัวอย่างของ containment hierarchy ลำดับชั้นของภาชนะ
Features ของ JComponent ที่น่านำไปใช้ในโปรแกรม
- Tool tips กำหนดข้อความโดย
setToolTipText(), ช่วยบอกเวลา user เอาเมาส์มาวางไว้. ดูเพิ่มเติมได้ที่ How to Set the Look and Feel - Support for layout ใน
Componentclass แม้จะมี methods ซึ่งเอาไว้ดู layout hint เช่นgetPreferredSizeandgetAlignmentX. ทางเลือกอื่นสำหรับ set layout hints,JComponentclass เพิ่ม setter methods —setPreferredSize,setMinimumSize,setMaximumSize,setAlignmentX, andsetAlignmentY. ขึ้นมา ดูเพิ่มที่ Laying Out Components Within a Container - Key bindings ทำให้ components ตอบสนองเมื่อ user กดปุ่ม keyboard ที่กำหนดไว้. เช่นเวลาเคอร์เซอร์อยู่บนปุ่ม การกด space bar ก็เหมือนกับการกดคลิ๊กบนปุ่มนั้น. look and feel เซต bindings ของการกดและปล่อย ปุ่ม Space และส่งผลนั้นไปที่ปุ่ม. เพิ่มเติมเกี่ยวกับ key bindings ดูที่ How to Use Key Bindings
.
การใช้ Text Components
| Method | Purpose |
|---|---|
void addMouseListener(MouseListener) void removeMouseListener(MouseListener) | Add or remove a mouse listener |
void addMouseMotionListener(MouseMotionListener) void removeMouseMotionListener(MouseMotionListener) | Add or remove a mouse motion listener |
void addKeyListener(KeyListener) void removeKeyListener(KeyListener) | Add or remove a key listener |
void addComponentListener(ComponentListener) void removeComponentListener(ComponentListener) | Add or remove a component listener |
void setTransferHandler(TransferHandler) TransferHandler getTransferHandler() | Set or remove the transferHandler property. The TransferHandler supports exchanging data via cut, copy, or paste to/from a clipboard as well a drag and drop. See Drag and Drop |
boolean contains(int, int) boolean contains(Point) | Determine whether the specified point is within the component. The argument should be specified in terms of the component's coordinate system. The two int arguments specify x and y coordinates, respectively. |
Component getComponentAt(int, int)Component getComponentAt(Point) | Return the component that contains the specified x, y position. The top-most child component is returned in the case where components overlap. This is determined by finding the component closest to the index 0 that claims to contain the given point via Component.contains(). |
อ้างอิง
จาวา ติวโตเรี่ยล
สมัครสมาชิก:
บทความ (Atom)