如何将 JButton 添加到我的全屏 java 程序中
我已经关注了youtube上的newbostons java游戏教程并成功创建了一个基础类将使用 screenmanager 类处于全屏模式。好吧,一切都很好,我可以绘制图像和字符串等,但是我到底如何添加 JButtons 等。
我已将我的代码上传到 Pastie.org,以便您可以看到它:)
I have followed thenewbostons java game tutorials on youtube and managed to create a base class which will be in full screen mode using a screenmanager class. Well all works just fine, I can draw images and strings and so on, but how the heck can I add JButtons etc etc.
I have uploaded my code on pastie.org so you can see it :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑以下代码:
导入javax.swing.JButton;
导入javax.swing.JFrame;
公共类NewClass5扩展JFrame
<代码>{
JButton b=new JButton("按钮");
NewClass5(){
this.add(b);
this.setSize(200, 200);
this.setVisible(true);
<代码>}
public static void main(String a[]){
new NewClass5();
<代码>}
<代码>}
consider following code :
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();
}
}
考虑提前添加按钮。不要让它可见。然后当你想提供该选项时,setVisible(true)。除非您有许多动态按钮并且需要即时更改或其他内容,否则我认为这应该可行。
Consider adding the button in ahead of time. Don't make it visible. Then when you want to give that option, setVisible(true). Unless you have many buttons that are dynamic and need to change on the fly or something, I think this should work.