我似乎無法弄清楚這一點。
請幫助我需要這個來解決我的項目。
呀我要補充這讓我張貼JLabel作爲背景圖片
import javax.swing.*;
import java.awt.*;
@SuppressWarnings("serial")
public class MainFrame extends JFrame {
public static void Draw(){
DrawFrame();
}
public static void DrawFrame(){
int h = 600;
int w = 340;
JFrame frame = new JFrame();
JLabel background1 = new JLabel(new ImageIcon("/res/mariocraft_main.png"));
frame.setResizable(false);
frame.setSize(h, w);
frame.setTitle("MarioCraft");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.add(background1);
background1.setVisible(true);
background1.setIcon(new ImageIcon("/res/mariocraft_main.png"));
background1.setText("Background failed to load");
}
}
-1什麼是你的問題的樣本代碼片段?而不是添加無意義的文本,也許你應該嘗試解釋你想做什麼更徹底 – PTBG
我的意思是我嘗試使用JLabel作爲背景。問題在標題 – Alek345
你在問什麼?你的代碼有什麼問題?請不要將代碼轉儲到問題中,然後說:「修復它」,解釋你想說的話。 –