私のイメージが自分のプログラムのバックグラウンドに表示されないのはなぜですか?私はすべてのステップを必要としたが、まだそれは表示されないことを意味する。コードは完全に実行されますが、画像は表示されません。ディレクトリはイメージの適切な場所に書き込まれます。私はguiとjavaを使用しています。誰も私には私の問題を解決するのに役立つことができれば、私は感謝:)ここに以下のコードは次のとおりです。java gui image problem:背景に表示されない
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class hehe extends JPanel{
public hehe(){
setOpaque(false);
setLayout(new FlowLayout());
}
public static void main (String args[]){
JFrame win = new JFrame("yooooo"); // it is automaticcally hidden
JPanel mainPanel = new JPanel(new BorderLayout());
win.add(mainPanel);
JLabel titleLabel = new JLabel("title boss");
titleLabel.setFont(new Font("Arial",Font.BOLD,18));
titleLabel.setForeground(Color.blue);
mainPanel.add(titleLabel,BorderLayout.NORTH);
win.setSize(382,269); // the dimensions of the image
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setVisible(true);
}
public void paint(Graphics g) {
Image a = Toolkit.getDefaultToolkit().getImage("C:\\Users\\andrea\\Desktop\\Gui\\car"); // car is the name of the image file and is in JPEG
g.drawImage(a,0,0,getSize().width,getSize().height,this);
super.paint(g);
}
}
拡張を行った、私はオブジェクトを作成しようとします – thegamer
多分あなたは新しいコードで質問を更新する必要があります –
あなたはこれを置くように意味:hehe c = new hehe(); //行をスキップするwin.add(c);それはあなたが意味することですか? – thegamer