2012-02-08 34 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)。除非你有很多动态的按钮,并且需要随时更改,否则我认为这应该起作用。

相关问题