Results 1 to 3 of 3
  1. #1
    Twister03 is offline Member
    Join Date
    Mar 2009
    Posts
    1
    Rep Power
    0

    Default Background in JFrame ( GUI).

    Hi all

    I have a problem and unfortunately i see i will be not able to solve it alone. I have a piece of code GUI and I want to set a image from internet as a background.Basicly i need a huge image over buttons. I know that on the internet I can find many solutions unfortunately I am new in java and i dont know how to use this solutions. I will be really grateful if someone will help me:)



    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;



    public class CustomerGUI extends JFrame implements ActionListener{
    JPanel panel = new JPanel();

    JButton add = new JButton("Add New Customer");
    JButton search = new JButton("Search Customer");
    JButton extras = new JButton("Add Extras");
    JButton booking = new JButton("Add Booking");
    JButton admin = new JButton("Administrator");


    public CustomerGUI()

    {
    /**
    * Constructor for objects of class CustomerGUI
    */


    super("Customers");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    GridLayout layout = new GridLayout(1,2,5,5);
    panel.setLayout(layout);

    add.addActionListener(this);
    search.addActionListener(this);
    extras.addActionListener(this);
    booking.addActionListener(this);
    admin.addActionListener(this);

    panel.add(add);
    panel.add(search);
    panel.add(extras);
    panel.add(booking);
    panel.add(admin);

    add(panel);
    pack();
    setVisible(true);
    }
    public class ImagePanel extends JPanel {
    }

    public void actionPerformed(ActionEvent e){
    Object source = e.getSource();
    //System.out.println(source);
    if(source==add){
    JFrame frame = new JFrame("Add Customer");
    AddCustomer add = new AddCustomer();
    frame.add(add);
    frame.pack();
    frame.setVisible(true);
    }
    else if(source==search){
    JFrame frame = new JFrame("Search Customer");
    SearchCustomer sc = new SearchCustomer();
    //remove(panel);
    frame.add(sc);
    frame.pack();
    frame.setVisible(true);
    }
    else if(source==extras){
    JFrame frame = new JFrame("Add Extras");
    AddExtras exts = new AddExtras();
    frame.add(exts);
    frame.pack();
    frame.setVisible(true);
    }
    else if(source==booking){
    JFrame frame = new JFrame("Add Booking");
    AddBooking bkng = new AddBooking();
    frame.add(bkng);
    frame.pack();
    frame.setVisible(true);
    }
    else if(source==admin){
    JFrame frame = new JFrame("Admin");
    DisplayQueryResults adm = new DisplayQueryResults();
    frame.add(admin);
    frame.pack();
    frame.setVisible(true);

    }
    }

    public static void main(String [] args){
    CustomerGUI cg = new CustomerGUI();




    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    I have a problem and unfortunately i see i will be not able to solve it alone. I have a piece of code GUI and I want to set a image from internet as a background.Basicly i need a huge image over buttons. I know that on the internet I can find many solutions unfortunately I am new in java and i dont know how to use this solutions.
    What do you mean by "huge image over buttons"? The more specific information you can provide, the more any of us can help? Are you trying to give your app a background image and place the buttons on top of this image? Are you trying to give the buttons themselves images?

    Also, when posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?

    To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:

    Java Code:
    [code]
      // your code goes here
      // notice how the top and bottom tags are different
    [/code]
    Finally, you'll want post code that compiles and runs by itself if possible, and definitely you want to only post code that relates to your problem.

    Best of luck.

  3. #3
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    I can't get it :( If you need a background why you say "huge image over buttons"?
    Decode your saying ;)

Similar Threads

  1. How to Run a .exe in background???
    By jazz2k8 in forum New To Java
    Replies: 9
    Last Post: 01-21-2011, 11:27 AM
  2. BackGround & ForeGround
    By hungleon88 in forum Advanced Java
    Replies: 3
    Last Post: 08-31-2008, 07:20 AM
  3. setting background color of JFrame form with NetBeans 6.1
    By onefootswill in forum New To Java
    Replies: 4
    Last Post: 08-12-2008, 07:02 AM
  4. Replies: 2
    Last Post: 03-24-2008, 05:29 AM
  5. Set the background in Java
    By barney in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •