Results 1 to 10 of 10

Thread: [RESOLVED] Adding image to Java Application

  1. #1

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Resolved [RESOLVED] Adding image to Java Application

    Hi to all,

    As a part of my college project i have to make an online auction application, I have made all except one thing. I need a client application to load item picture.
    The idea was that the picture will be on server, and its address stored in a database. Client clicks on an item, application loads its image address from database and opens that image in current frame, or in some of its component.

    So im stuck here, i have image address in a String but i cannot load the image because i dont know how.

    Help please!



    I have the second question.
    How to load local picture into applet, from the same disk.
    I need an applet on a web page and it to load the picture from its directory.
    Just need the code to load the picture.
    Last edited by Dungeon Keeper; Jan 30th, 2009 at 06:43 AM.

  2. #2
    Lively Member
    Join Date
    Dec 2008
    Location
    Banglore
    Posts
    95

    Smile Re: Adding image to Java Application

    Well i am having some code do one thing i am sending the code if it works fine not means u just send me a copy code of ur project.
    Code:
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.BorderLayout;
     
    public class GUI2 extends JFrame
    {
    	ImageIcon icon;
    	Image image;
     
    	public GUI2()
    	{
    		icon = new ImageIcon("Winter.jpg");
    		JPanel panel = new JPanel()
    		{			
    			protected void paintComponent(Graphics g)
    			{
    				//  Dispaly image at full size
    				g.drawImage(icon.getImage(), 0, 0, null); 	
    				super.paintComponent(g);
    			}
    		};
    		panel.setOpaque( false );
    		panel.setPreferredSize( new Dimension(500, 500) );	
    		getContentPane().add( panel ); 
     		panel.setLayout(new BorderLayout()); 		
     		JPanel southPanel = new JPanel();
     		JButton button = new JButton( "Hello" );
     		southPanel.setOpaque(true);
     		button.setOpaque(true);
     		southPanel.add(button); 		
     		add(southPanel, BorderLayout.NORTH); 	
     	//	southPanel.add(button);
     	//	southPanel.add(b);		
    	} 
    	public static void main(String [] args)
    	{
    		GUI2 frame = new GUI2();
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setSize(450,  250);
    		frame.setLocationRelativeTo( null );
    		frame.setVisible(true);
    	}
    }
    Success = 1 % Knowledge + 99 % Hard work

  3. #3

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: Adding image to Java Application

    Thank you very much. Ive got the point how is it done

    Where does this Winter.jpg needs to be placed? In which folder?
    Where my .class files are?

  4. #4
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Adding image to Java Application

    the applet will be running on the client and you wanted your pictures to be on a server.

    Ensure that the directory where the images are on the server is accessible
    and from that you can try

    icon = new ImageIcon("\\\\server\\imagedir\\Winter.jpg");

  5. #5

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: Adding image to Java Application

    thanks oceanebelle but i think ill make an applet on server side
    Its easier this way.

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Adding image to Java Application

    Quote Originally Posted by Dungeon Keeper
    thanks oceanebelle but i think ill make an applet on server side
    Its easier this way.
    Sorry to disappoint you but Applets are all client-side
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  7. #7

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: Adding image to Java Application

    Yeah i know but its different if applet is on user pc or on server pc

  8. #8
    Lively Member
    Join Date
    Dec 2008
    Location
    Banglore
    Posts
    95

    Re: Adding image to Java Application

    well i am not clear with ur replay give me detailed thing i will try to help and the jpg file has to place in the directory where the oceanebelle given u the way u have
    Success = 1 % Knowledge + 99 % Hard work

  9. #9

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: Adding image to Java Application

    Thanks for help maheshkanda i think ill manage to do it on my own from here. Thanks a lot for help!

  10. #10
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: [RESOLVED] Adding image to Java Application

    good luck

Posting Permissions

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



Click Here to Expand Forum to Full Width