salve a tutti ho scritto questo semplice codice in Java che applica un'immagine di sfondo con 4 pulsanti colorati.Il mio unico problema è che lo sfondo si sovrappone ai pulsanti e solo quando passo sopra con il mouse sui pulsanti questi "affiarano" sopra lo sfondo.Come posso risolvere questa situazione? GRAZIE
IL MAIN
LA classe che gestisce la graficacodice:public class Principale { public static void main(String[] args) { Gestione f=new Gestione(); f.setTitle("gioco"); f.setSize(400,300); f.setVisible(true); f.setLocation(250,100); } }
codice:import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Gestione extends JFrame { private JPanel p=new JPanel(); private JButton uno = new JButton(); private JButton due = new JButton(); private JButton tre = new JButton(); private JButton qua = new JButton(); public Gestione(){ p.setLayout(null); uno.setBackground(Color.yellow); due.setBackground(Color.yellow); tre.setBackground(Color.yellow); qua.setBackground(Color.yellow); uno.setBounds(40,150,70,70); due.setBounds(120,150,70,70); tre.setBounds(200,150,70,70); qua.setBounds(280,150,70,70); p.add(uno); p.add(due); p.add(tre); p.add(qua); this.getContentPane().add(p); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } Image sfondo = Toolkit.getDefaultToolkit().getImage("C:/sfon.jpg"); public void paint(Graphics g) { super.paint(g); Insets i = getInsets(); g.drawImage(sfondo,i.left,i.top, 400, 300,this); } }

Rispondi quotando