2012-02-08 33 views
2

我跟着thenewbostons java game tutorials on youtube,並設法創建一個基類,它將使用screenmanager類以全屏模式。那麼所有的作品就好了,我可以繪製圖像和字符串等,但到底我怎麼能添加Jbutton將等等等等如何添加一個JButton到我的全屏java程序

我已上載pastie.org我的代碼,所以你可以看到它:)

Main.java

Screen

BaseFrame [the abstract frame]

Menu Frame [Inheritted from BaseFrame]

+1

爲了更快提供更好的幫助,請發佈[SSCCE](http://sscce.org/)。 – 2012-02-09 05:15:33

回答

2

考慮下面的代碼: import javax.swing.JButton;
import javax.swing.JFrame;
public class NewClass5 extends JFrame
{
JButton b=new JButton("button");
NewClass5(){
this.add(b);
this.setSize(200, 200);
this.setVisible(true);
}
public static void main(String a[]){
new NewClass5();
}
}

2

考慮的時間提前添加按鈕。不要讓它可見。然後,當你想給這個選項,setVisible(true)。除非你有很多動態的按鈕,並且需要隨時更改,否則我認爲這應該起作用。

相關問題