salve a tutti ho creato questo semplice giochino ma il problema è che l'immagine di sfondo su alcuni pc viene visualizzata correttamente e in altri viene visualizzata solo una piccola parte di immagine dietro i valori delle vite e dei punti quando si aggiornano. Secondo me è un problema di compatibilità perchè il codice funziona però non so come risolvere.grazie per l'aiuto
codice:public class Principale { public static void main(String[] args) { Gestione f=new Gestione(); f.setTitle("Gioco by Dario Asciolla"); f.setSize(400,300); f.setVisible(true); f.setLocation(250,100); f.pulsanti(); } } import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.Random; public class Gestione extends JFrame { private JLabel punti =new JLabel("0"); private JLabel vite =new JLabel("3"); private JButton uno = new JButton(); private JButton due = new JButton(); private JButton tre = new JButton(); private JButton qua = new JButton(); private int s=0; private int tempo=1300; private int pun=0; private int vit=3; private boolean premuto=true; private Timer timer = new Timer(1300,null); Image sfondo = Toolkit.getDefaultToolkit().getImage("sfon.jpg"); public Gestione(){ JPanel p = new JPanel() { protected void paintComponent(Graphics g) { g.drawImage(sfondo, 0,0, null); super.paintComponent(g); } }; p.setOpaque(false); 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); punti.setBounds(330,42,20,10); vite.setBounds(60,42,10,10); p.add(punti); p.add(vite); p.add(uno); p.add(due); p.add(tre); p.add(qua); add(p); } public void pulsanti(){ timer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // if(premuto==false) vitameno(); casuali(); switch(s){ case 0: uno.setBackground(Color.red); due.setBackground(Color.yellow); tre.setBackground(Color.yellow); qua.setBackground(Color.yellow); break; case 1: due.setBackground(Color.red); uno.setBackground(Color.yellow); tre.setBackground(Color.yellow); qua.setBackground(Color.yellow); break; case 2: tre.setBackground(Color.red); due.setBackground(Color.yellow); uno.setBackground(Color.yellow); qua.setBackground(Color.yellow); break; case 3: qua.setBackground(Color.red); due.setBackground(Color.yellow); tre.setBackground(Color.yellow); uno.setBackground(Color.yellow); break; } } }); timer.start(); uno.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e){ timer.setDelay(tempo=tempo-10); if(s==0 && !premuto){ incrementopun(); premuto=true; } else { vitameno(); } } }); qua.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e){ timer.setDelay(tempo=tempo-10); if(s==3 && !premuto){ incrementopun(); premuto=true; }else { vitameno(); } } }); due.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e){ timer.setDelay(tempo=tempo-10); if(s==1 && !premuto){ incrementopun(); premuto=true; }else { vitameno(); } } }); tre.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e){ timer.setDelay(tempo=tempo-10); if(s==2 && !premuto){ incrementopun(); premuto=true; }else { vitameno(); } } }); } public void casuali(){ int appo; Random random = new Random(); appo=random.nextInt(4); if(appo==s) casuali(); else s=appo; premuto=false; } public void incrementopun(){ pun++; punti.setText(Integer.toString(pun)); } public void vitameno(){ vit--; vite.setText(Integer.toString(vit)); if(vit==0){ int n=JOptionPane.showConfirmDialog(this,"punti : "+Integer.toString(pun)+" vuoi rigiocare?","HAI PERSO",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE); if(n== JOptionPane.NO_OPTION) System.exit(0); else { tempo=1300; pun=0; vit=3; vite.setText(Integer.toString(vit)); punti.setText(Integer.toString(pun)); timer.setDelay(tempo); } } } }

Rispondi quotando