Re: [問題] DDR程式架構
※ 引述《maxisam (偽.強者)》之銘言:
: 想請問一下前輩們 我這樣設計的架構有沒有問題
: DDR 基本上是用很簡單的版本 就是有一個bar會從上面掉下來 然後在特定的位置 按按鈕
: 他就會消失
: 我的想法如下
: 問題來了 我本來想是要做一個Class: MoveLine extend Thread
: 然後 再把這個moveLine 放在overwrite mpaintComponent(Graphics g)
: 然後把 Graphics g 在initiate moveLine的時候 傳入其constructor
: 然後在他的run 裡面做上面那幾個迴圈
: 不過 這樣g都一直沒有傳進去 (g在constructor內有接收到)
: 但是 run裡面的g都是null
這部份要看詳細的碼才知道原因,
不過本來這樣把變數亂傳就是不好的,可能會造成ref混淆。
你如果需要這樣做的話 ,
可以考慮 傳入目標的元件(ex Frame)做 getGraphics() .
應該可以確保取得 Graphics 的資料
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Component.html#getGraphics()
btw盡量讓繪圖的動作簡單化,
用多一點的計算取代多執行緒,在管理上會比較方便......
其實我很久沒寫Java GUI了,以上就僅供參考吧。XD
--
String temp="relax"; | Life just like programing
while(buringlife) String.forgot(temp); | to be right or wrong
while(sleeping) brain.setMemoryOut(); | need not to say
stack.push(life.running); | the complier will
stack.push(scouting.buck()); | answer your life
stack.push(bowling.practice()); | Bone everything
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.134.27.68
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 2 之 8 篇):