0
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.*;

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

public class Character {

    private JFrame characterWindow;

    private JPanel allPanels, imagePanelHero, imagePanelVillain;

    private JButton HeroBtn, VillainBtn;

    private JLabel textLabel, heroTextLabel, villainTextLabel, imageLabel;

    public Character()

    {
        allPanels = new JPanel();
        allPanels.setLayout(null);
        allPanels.setBackground(new Color(255,255,255));

        imagePanelHero = new JPanel();
        imagePanelHero.setBackground(Color.BLACK);
        imagePanelHero.setBounds(205,150,300,300);
        ImageIcon pic1 = new ImageIcon("src/superman1.jpg");
        imagePanelHero.add(new JLabel(pic1));
        this.add(imagePanelHero);
        this.pack();
        this.setVisible(true);

        allPanels.add(imagePanelHero);

        imagePanelVillain = new JPanel();
        imagePanelVillain.setBackground(Color.BLACK);
        imagePanelVillain.setBounds(790,150,300,300);
        allPanels.add(imagePanelVillain);
        ImageIcon pic2 = new ImageIcon("src/Lex1.jpg");
        imagePanelVillain.add(new JLabel(pic2));
        this.pack();
        this.setVisible(true);

        textLabel = new JLabel("Pick: Hero or Villain? ", JLabel.CENTER);
        textLabel.setBounds(20,40,1280,30);
        allPanels.add(textLabel);

        HeroBtn = new JButton("Hero");
        HeroBtn.setBounds(300,485,100,50);
        HeroBtn.setBackground(Color.BLUE);
        HeroBtn.setForeground(Color.WHITE);

        heroTextLabel = new JLabel("Fight for the side of Good and save the people of the world. ", JLabel.CENTER);
        heroTextLabel.setBounds(0,575,715,30);
        allPanels.add(heroTextLabel);

        VillainBtn = new JButton("Villain");
        VillainBtn.setBounds(890,485,100,50);
        VillainBtn.setBackground(Color.BLUE);
        VillainBtn.setForeground(Color.WHITE);

        villainTextLabel = new JLabel("Fight for evil and chaos creating mayhem wherever you go.? ", JLabel.CENTER);
        villainTextLabel.setBounds(100,575,1705,30);
        allPanels.add(villainTextLabel);

        allPanels.add(HeroBtn);
        allPanels.add(VillainBtn);



        HeroBtn.addActionListener(new ActionListener()
        {
            public void actionPerformed (ActionEvent event)
            {
                callHero();
            }
        });

        VillainBtn.addActionListener(new ActionListener()
        {
            public void actionPerformed (ActionEvent event)
            {
                callVillain();
            }
        });

        characterWindow = new JFrame();
        characterWindow.setTitle("Hero or Villain?");
        characterWindow.setSize(1280, 720);
        characterWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        characterWindow.setVisible(true);
        characterWindow.add(allPanels);
        characterWindow.setResizable(true);
        characterWindow.setLocationRelativeTo (null);
        ImageIcon pic3 = new ImageIcon("src/Metropolis.jpg");
        characterWindow.add(new JLabel(pic3));
        this.pack();
        this.setVisible(true);

    }   

    private void setVisible(boolean b) {
        // TODO Auto-generated method stub
    }

    private void pack() {
        // TODO Auto-generated method stub
    }

    private void add(JPanel imagePanelHero2) {
        // TODO Auto-generated method stub
    }

    protected void callHero() {
        // TODO Auto-generated method stub  
    }

    protected void callVillain() {
        // TODO Auto-generated method stub
    }

    public static void main (String args [])
    {
        Character character = new Character();
    }


}

I am trying to create a JFrame that has a background image of a city on it, but when I run my program the background colour of that is on the jframe appears in front of the image, the image is being displayed though, because when I resize the window I can see the edge of the image behind the background colour, does anyone have any simple ideas how to fix this, i.e. make the background colour transparent or move the image infront of the colour, im a beginner with code so im not sure on some aspects which is why a simple answer would be greatly appreciated.

camickr
  • 321,443
  • 19
  • 166
  • 288
Ryukashin
  • 1
  • 2
  • You should post your code – ControlAltDel Apr 08 '15 at 19:50
  • Try taking a look at http://stackoverflow.com/questions/1064977/setting-background-images-in-jframe - it should give you plenty of code examples. – Ewald Apr 08 '15 at 19:50
  • @Ryukashin, don't post code in comments as you can see the code is hard to read. Edit your question and post the code. Also, variable names should NOT start with an upper case character. So fix that BEFORE posting the code in the question. – camickr Apr 08 '15 at 20:27

0 Answers0