我有一個類Game
,它擴展了JFrame並創建了我想要繪製的窗口。然後我有這個類Die
,它繪製我想要的。從Game
我可以在Die
類中調用setup()
方法,但是如何調用paint()方法?從不擴展JFrame的類中調用paint方法
public class Die
{
private int xA, yA;
private int dieNumber;
public void setup(int someX, int someY, int someValue) {
dieNumber = someValue;
xA = someX;
yA = someY;
}
public void paint(Graphics pane) {
drawBlank(pane);
if (dieNumber == 1){
drawOne(pane); }
else if (dieNumber == 2){
drawTwo(pane); }
else if (dieNumber == 3){
......
你剛纔不是問這個?無論如何,您應該嘗試創建併發佈一個我們可以運行和編譯的小程序[最小示例程序或MCVE](http://stackoverflow.com/help/mcve),這會向我們展示您的問題。還有很多相關代碼需要向我們展示 - 但沒有向我們展示太多的代碼,這是MCVE的幫助。你可能在JPanel的'paintComponent(...)'方法中做圖形,如果是,應該調用你的Die對象的paint方法在paintComponent方法中。但是,我只是在瘋狂地猜測。請展示更多。 – 2014-10-20 21:50:09
[Again](http://stackoverflow.com/questions/26472497/java-calling-paint-method-from-different-class)?我[說](http://stackoverflow.com/questions/26474594/java-calling-paint-method-from-window-method-in-another-class)。 – 2014-10-20 21:54:58
@HovercraftFullOfEels我正在做一個JFrame的繪圖(...)。我在描述中提到了它。如果不夠清楚,我很抱歉。但爲什麼我不能從setup()調用paint()? – John 2014-10-20 21:55:25