Announcement

Collapse
No announcement yet.

auf JLabel malen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • auf JLabel malen

    hallo!
    habe folgendes problem: ich hab ein JFrame mit einem JPanel wo ein hintergrundbild drauf ist. auf diesem JPanel werden nun 6 JLabels angeordnet. auf diesen labels will ich ein bild mit tranparenten hintergrund malen lassen. wenn ich auf den labels einfach ein icon drauf setze wird das hintergrund bild weis wo eigentlich transparenz sein sollte. ok, hier mal der code.

    import java.awt.Graphics;
    import java.awt.GridLayout;
    import java.awt.Image;

    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;

    import zuul.core.Game;
    /**
    * This class represents the GUI of the player's bag, it is implemented according to the singleton pattern.
    * @author Daniel Sander
    * @version 13.01.2009
    */
    public class BagGUI extends JFrame{

    private static final long serialVersionUID = 1L;

    private ImageIcon icon;

    //the labels
    private JLabel bag1;
    private JLabel bag2;
    private JLabel bag3;
    private JLabel bag4;
    private JLabel bag5;
    private JLabel bag6;

    private ImageIcon disabledIcon;
    private ImageIcon test;

    // private Thread thread;

    private static BagGUI instance;
    /**
    * the constructor
    */
    private BagGUI(){


    setLayout(new GridLayout(3,2));

    setLocationRelativeTo(null);
    setResizable(false);

    // thread = new Thread();
    //sets the background image;
    setContentPane(new BackGroundPane("sv_bagGUIPanel.jpg"));

    // disabledIcon = new ImageIcon(Game.getInstance().getPathSource() + "sv_bagGUILabel.jpg");

    test = new ImageIcon(Game.getInstance().getPathSource() + "sv_sword.jpg");

    add(getBag1());
    add(getBag2());
    add(getBag3());
    add(getBag4());
    add(getBag5());
    add(getBag6());

    setSize(135, 220);
    }
    /**
    * Returns the only instance.
    * @return instance
    */
    public static BagGUI getInstance(){
    if(instance == null){
    instance = new BagGUI();
    return instance;
    }
    return instance;
    }

    private JLabel getBag1() {

    if(bag1 == null) {
    bag1 = new JLabel();
    // bag1.setIcon(test);
    }

    return bag1;
    }

    private JLabel getBag2() {

    if(bag2 == null) {
    bag2 = new JLabel();
    // bag2.setIcon(test);
    }
    return bag2;
    }

    private JLabel getBag3() {

    if(bag3 == null) {
    bag3 = new JLabel();
    // bag3.setIcon(test);
    }
    return bag3;
    }

    private JLabel getBag4() {

    if(bag4 == null) {
    bag4 = new JLabel();
    // bag4.setIcon(test);
    }
    return bag4;
    }

    private JLabel getBag5() {

    if(bag5 == null) {
    bag5 = new JLabel();
    // bag5.setIcon(test);
    }
    return bag5;
    }

    private JLabel getBag6() {

    if(bag6 == null) {
    bag6 = new JLabel();
    // bag6.setIcon(test);
    }
    return bag6;
    }
    //inner class, to display the background image
    class BackGroundPane extends JPanel{

    private static final long serialVersionUID = 1L;

    private Image img = null;
    /**
    * The constructor
    * @param imagefile
    */
    public BackGroundPane(String imagefile) {
    super(new GridLayout(3,2));

    if (imagefile != null) {
    img = SpriteStore.getInstance().get(imagefile);
    }
    }

    protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawImage(img,0,0,this.getWidth(),this.getHeight (),this);
    }
    }




    }

  • #2
    sv_sword.jpg -> Ein JPG kennt keine Transparenz
    Christian

    Comment


    • #3
      .. bin ich dumm^^.. gimp sagts mir auch noch... thx für die schnelle antwort!

      Comment

      Working...
      X