Tags:

ใครที่มีความสามารถ หรือมีความสนใจในภาษา 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);

}

}

Get latest news from Blognone
By: JavaDevil
iPhoneUbuntuIn Love
on 10 February 2009 - 20:51 #84843

ขอความกระจ่างของคำถามมากกว่านี้ได้หรือเปล่า

By: Nohohon
iPhoneAndroidBlackberrySymbian
on 10 February 2009 - 22:12 #84873
Nohohon's picture

แล้วแต่ครับ ตอบยากเพราะคำถามสั้นจัง

By: bow_der_kleine
WriterAndroidUbuntu
on 10 February 2009 - 22:23 #84878
bow_der_kleine's picture

ส่วนมากเขาส่งผ่าน method parameter ครับ

BioLawCom.De

By: mr_tawan
ContributoriPhoneAndroidWindows
on 10 February 2009 - 22:56 #84884
mr_tawan's picture

ส่งให้คลาส ... ก็ผ่านทาง static method สิครับ (คลาสมันรับค่าทางอื่นมิได้นิ ?) เอ๊ะ หรือจะผ่านทาง static public variable ... ไม่ดีมั้ง ??

ถ้าส่งเข้า object ก็ผ่านทาง instance method ...

ผมเข้าใจคำถามถูกมั้ยเนี่ย ???

ThaiGameDevX -- The First Game Developer Community in Thailand.


  • 9tawan.net บล็อกส่วนตัวฮับ
By: kowito2
Android
on 10 February 2009 - 23:41 #84895

ยังพยายามตอบกันได้เนอะ lol

By: khajochi
WriteriPhoneIn Love
on 11 February 2009 - 15:17 #85018
khajochi's picture

สร้าง window, panel หรือ frame ก่อนแล้วค่อย add component ลงไป

ตัวอย่าง http://kickjava.com/424.htm

ปล. น่าจะตั้งชื่อกระทู้ให้สื่อนิดนึงนะครับ มีแต่ Java โต้งๆ ไม่น่าจะดี

---
Khajochi Blog : It's not a Bug ... It's a Feature


แฟนพันธุ์แท้สตีฟจ็อบส์ | MacThai.com

By: tuckclub on 11 February 2009 - 15:20 #85020

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); } }

By: yochi403 on 11 February 2009 - 18:13 #85046

0

เดวลองไปรันดูมั่ง