BAckground image in JFrame?
Author |
Message |
Krocker
|
Posted: Mon Jan 09, 2012 10:36 am Post subject: BAckground image in JFrame? |
|
|
hiya guys, ok so i was wondering is there a way of adding a background image into my program. I have a gif image in the same folder as my program, and i have tried a lot of different things, but for some reason, when i compile, nothing shows up just my program with a blank/original background. Im also having trouble moving the buttons around, they dont seem to want to move. Heres the codes for my program if you need them:
code: |
package kcleaner;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.border.Border;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.awt.*;
public class KCleaner extends JFrame implements ActionListener
{
public JFrame f1 = new JFrame (" K C l e a n e r");
public JPanel p1 = new JPanel ();
public JButton b1 = new JButton ("Clean");
public JButton b2 = new JButton ("ABOUT");
public Container pane;
public Image im = Toolkit.getDefaultToolkit ().getImage ("kcleaner/Icon.gif");
// public Image bg = Toolkit.getDefaultToolkit ().getImage ("kcleaner/Background.gif");
ImageIcon bg = new ImageIcon ("kcleaner/Background.gif");
public JLabel bgpic = new JLabel (bg);
public KCleaner ()
{
f1.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
f1.setIconImage (im);
b1.addActionListener (this);
b2.addActionListener (this);
f1.setContentPane (p1);
f1.setSize (400, 400);
p1.add (b1);
p1.add (b2);
p1.add (bgpic);
f1.setVisible (true);
}
public void actionPerformed (ActionEvent e)
{
dProcess method = new dProcess ();
if (e.getSource () == b1)
{
String drive = JOptionPane.showInputDialog (null, "Please Enter Your Main Hard Drive Letter", "Hardrive", JOptionPane.QUESTION_MESSAGE);
// String user = JOptionPane.showInputDialog(null, "Please Enter The User Accout Name", "User Account", JOptionPane.QUESTION_MESSAGE );
String folder = drive.toUpperCase () + ":\\Nexon/Combat Arms/BlackCipher";
int value = 25;
// int i;
if (folder == null)
{
JOptionPane.showMessageDialog (null, "Directory does not exist.");
}
else
{
JOptionPane.showMessageDialog (null, "KCleaner is Done!");
method.directory (new File (folder));
}
}
else if (e.getSource () == b2)
{
JOptionPane.showMessageDialog (null, "KCLEANER V1.0 by Krocker");
}
}
public static void main (String[] args)
{
new KCleaner ();
}
}
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|