Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: background image in java form

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default background image in java form

    This is my java code.What I'm trying to do is,keep the image as background and keep the buttons on top.But the image overwrites my base form.I'm only a beginner.so please help me.
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.*;
    class petbegin extends JPanel
    {
      JLabel title;
      JLabel caption;
      JButton chief;
      JButton vet;
      JButton recept;
      public petbegin()
      {
        setLayout(null);
        title=new JLabel("A VET'S PET");
        caption=new JLabel("Nothing but the best for your pet!");
        chief=new JButton("Chief Doctor's Login");
        vet=new JButton("Assistant Vets' Login");
        recept=new JButton("Receptionist's Login");
        Font f1=new Font("Castellar",Font.BOLD,28);
        Font f=new Font("Castellar",Font.BOLD,32);
        Font f2=new Font("Calibri",Font.BOLD,20);
        title.setFont(f);
        caption.setFont(f1);
        chief.setFont(f2);
        vet.setFont(f2);
        recept.setFont(f2);
     
        add(title);
        add(caption);
        add(chief);
        add(vet);
        add(recept);
        title.setBounds(335,100,500,40);
        caption.setBounds(155,180,900,30);
        chief.setBounds(285,290,300,30);
        vet.setBounds(260,370,350,30);
        recept.setBounds(285,450,300,30);
     
       }
      }
      class imageframe extends JPanel
      {
        Image img=new ImageIcon("welcome.jpg").getImage();
     
     
        public void paintComponent(Graphics g)
      {
       g.drawImage(img,0,0,this);
      }
     }
      class space extends JPanel
     
      {
     
     
      }
     
     
     
      class welcome extends JFrame
      {
     
        public static void main(String args[])
        {
          JPanel spc=new space();
          spc.setLayout(new OverlayLayout(spc));
          spc.add(new imageframe(),BorderLayout.CENTER);
     
     
            spc.add(new petbegin(),BorderLayout.CENTER);
     
            welcome t=new welcome();
            t.setContentPane(spc);
            t.setVisible(true);
            t.setSize(1000,650);
      }
     }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: background image in java form

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Be sure the code has proper formatting with indentations showing logic nesting levels.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: background image in java form

    yeah done editing.Thanks for telling me,I'm new to this forum!

Similar Threads

  1. A Background Image
    By Randor in forum AWT / Java Swing
    Replies: 6
    Last Post: November 14th, 2012, 05:28 PM
  2. Replies: 1
    Last Post: August 4th, 2012, 10:02 AM
  3. Cant get background image to take up whole panel
    By Lanuk in forum AWT / Java Swing
    Replies: 1
    Last Post: December 13th, 2011, 08:26 AM
  4. Background image trouble on GUI.
    By Pydra in forum AWT / Java Swing
    Replies: 2
    Last Post: July 7th, 2011, 11:44 AM
  5. Background image on GUI
    By OBLITERATOR in forum AWT / Java Swing
    Replies: 3
    Last Post: March 5th, 2010, 12:10 PM

Tags for this Thread