Ave, ho creato un codice che generi una finestra con sfondo ma nn mi visualizza il bottone. Dove sbaglio?
codice:
package din;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Main extends JFrame {
String percorso = "./temp/1.jpg";
File sfondo = new File(percorso);
public Main() throws IOException {
BufferedImage image = ImageIO.read(sfondo);
JLabel label = new JLabel(new ImageIcon(image));
JFrame window = new JFrame("DIN");
window.setSize(400,400);
window.add(label);
JButton bottone = new JButton("OK");
label.add(bottone);
window.setVisible(true);
window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public static void main(String[] args) throws IOException {
Main principale = new Main();
}
}