Witam.
Chciałbym dodać do prostej apki tło w postaci png. Jednak gdy dodaje je w ten sposób setContentPane(new JLabel(ImageIcon(ImageIO.read(getClass().getResourceAsStream("/drawable/background.png")));
inne komponenty zostaja przysłonione. Wszystkie ikonki są umiejscowione w katalogu /drawable w pliku wykonywalnym .jar. Oto wygląd apki bez mojej kulawej implementacji tła apki:
public TTTFrame(){
setTitle(TITLE);
setBounds(DEFAULT_X_BOUND, DEFAULT_Y_BOUND, DEFAULT_WIDTH, DEFAULT_HEIGHT);
setResizable(isResizeable);
try{
blank=new ImageIcon(ImageIO.read
(getClass().getResourceAsStream("/drawable/blank.png")));
circle=new ImageIcon(ImageIO.read
(getClass().getResourceAsStream("/drawable/circle.png")));
close=new ImageIcon(ImageIO.read
(getClass().getResourceAsStream("/drawable/close.png")));
}
catch(Exception e){};
//Setting Internal layout
//Header of application
header=new JPanel();
this.getContentPane().add(header, BorderLayout.NORTH);
hGrid=new GridLayout(1, 2, 10, 10);
header.setLayout(hGrid);
header.add(new JLabel("It's turn for:"));
turnFor=new JLabel("Circle");
turnFor.setHorizontalAlignment(SwingConstants.RIGHT);
header.add(turnFor);
//Center Section.
battleField=new JPanel();
this.getContentPane().add(battleField, BorderLayout.CENTER);
cGrid=new GridLayout(3,3,10,10);
battleField.setLayout(cGrid);
for (int i=0;i<fieldButton.length;i++) {
fieldButton[i]=new ImageButton(blank);
fieldButton[i].addActionListener(spacePressed);
battleField.add(fieldButton[i]);}
//footer
footer=new JPanel();
this.getContentPane().add(footer, BorderLayout.SOUTH);
resetButton=new JButton("Play Again");
resetButton.addActionListener(reset);
footer.add(resetButton);
}
Proszę o wskazanie w jaki sposób w poprawny sposob ustawic tło tej aplikacji
Pozdrawiam:)