【发布时间】:2021-09-12 00:43:59
【问题描述】:
我想在 JFrame 中添加背景,所以我在 YouTube 上搜索并找到了一个视频,但它不起作用我尝试了另一个,但它也不起作用所以我的代码有什么问题 因为我一直在启动它只是不存在但 Eclipse 并没有标记任何错误。
package Pack;
import javax.swing.*;
public class Gui {
public Gui(){
JLabel background;
Var.jf = new JFrame();
Var.jf.setSize(Var.screenwidth, Var.screenheight);
Var.jf.setTitle("test");
Var.jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Var.jf.setResizable(false);
Var.jf.setVisible(true);
Var.jf.setLocationRelativeTo(null);
Var.jf.setLayout(null);
ImageIcon img = new ImageIcon("Bilder/Testbild");
background = new JLabel("",img,JLabel.CENTER);
background.setBounds(0,0,1000,1000);
Var.jf.add(background);
Var.Buttonxstart = new JButton("Start");
Var.Buttonxstart.setBounds(300,220,400,120);
Var.jf.add(Var.Buttonxstart);
Var.Buttonxclose = new JButton("Exit");
Var.Buttonxclose.setBounds(300,440,400,120);
Var.jf.add(Var.Buttonxclose);
}
}
.
package Pack;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Var {
static JFrame jf;
static int screenheight = 1000;
static int screenwidth = 1000;
static JButton Buttonxstart;
static JButton Buttonxclose;
}
【问题讨论】:
标签: java swing background jframe