ใครที่มีความสามารถ หรือมีความสนใจในภาษา JAVA ขอให้มาช่วยตอบปัญหา-ตั้งปัญหา ทางด้านนี้ด้วย
การส่งค่า Graphic ให้กับ class จะส่งผ่านกันแบบไหน
//main
{...
Double px = Double.parseDouble(st.nextToken());
Double py = Double.parseDouble(st.nextToken());
DrawComponent point = new DrawComponent(px,py);//บรรทัดนี้
จะส่งค่าให้คลาสยังงัย เพื่อเอาไปพลอตจุด
...}
//
class DrawComponent extends JComponent{
public double _x;
public double _y;
public void paintComponent(Graphics g){
Graphics2D g2 = (Graphics2D) g;
double width = 5;
double height = 5;
Rectangle2D rect = new Rectangle2D.Double(_x,_y,width,height);
g2.draw(rect);
}
}
ขอความกระจ่างของคำถามมากกว่านี้ได้หรือเปล่า
แล้วแต่ครับ ตอบยากเพราะคำถามสั้นจัง
ส่วนมากเขาส่งผ่าน method parameter ครับ
BioLawCom.De
ส่งให้คลาส ... ก็ผ่านทาง static method สิครับ (คลาสมันรับค่าทางอื่นมิได้นิ ?) เอ๊ะ หรือจะผ่านทาง static public variable ... ไม่ดีมั้ง ??
ถ้าส่งเข้า object ก็ผ่านทาง instance method ...
ผมเข้าใจคำถามถูกมั้ยเนี่ย ???
ThaiGameDevX -- The First Game Developer Community in Thailand.
ยังพยายามตอบกันได้เนอะ lol
สร้าง window, panel หรือ frame ก่อนแล้วค่อย add component ลงไป
ตัวอย่าง http://kickjava.com/424.htm
ปล. น่าจะตั้งชื่อกระทู้ให้สื่อนิดนึงนะครับ มีแต่ Java โต้งๆ ไม่น่าจะดี
---
Khajochi Blog : It's not a Bug ... It's a Feature
แฟนพันธุ์แท้สตีฟจ็อบส์ | MacThai.com
public class Driver { public static void main(String[] args) { StringTokenizer st = null;
Double px = Double.parseDouble(st.nextToken()); Double py = Double.parseDouble(st.nextToken()); DrawComponent point = new DrawComponent(px, py); } }
public class DrawComponent extends JComponent { private double _x; private double _y;
public DrawComponent(double _x, double _y) { this._x = _x; this._y = _y; }
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; double width = 5; double height = 5; Rectangle2D rect = new Rectangle2D.Double(_x, _y, width, height); g2.draw(rect); } }
0
เดวลองไปรันดูมั่ง