alessia86
22-08-2009, 09:40
Salve sto provando ad inserire un'immagine come sfondo..solo che l'immagine me la visualizza però non la mette a schermo intero..ma la visualizza a metà..Il codice che ho scritto è qst:
//classe Frame
public class Frame extends JFrame {
public Frame(){
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension d=kit.getScreenSize();
L=new String();
setSize(d.width,d.height);
Pannello panel = new Pannello(new ImageIcon("Immagini/gioco2.gif").getImage());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(panel);
setVisible(true);
}
}
//CLASSE PANNELLO
public class Pannello extends JPanel{
public Pannello(String img){
this(new ImageIcon(img).getImage());
}
public Pannello(Image img){
this.img=img;
Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
setLayout(null);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawImage(img,0,0,null);
}
Spero che qualcuno possa aiutarmi..Vi ringrazio :)
//classe Frame
public class Frame extends JFrame {
public Frame(){
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension d=kit.getScreenSize();
L=new String();
setSize(d.width,d.height);
Pannello panel = new Pannello(new ImageIcon("Immagini/gioco2.gif").getImage());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(panel);
setVisible(true);
}
}
//CLASSE PANNELLO
public class Pannello extends JPanel{
public Pannello(String img){
this(new ImageIcon(img).getImage());
}
public Pannello(Image img){
this.img=img;
Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
setLayout(null);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawImage(img,0,0,null);
}
Spero che qualcuno possa aiutarmi..Vi ringrazio :)