[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!
:wave:
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.
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);
}
}
Re: Adding image to Java Application
Thank you very much. Ive got the point how is it done :D
Where does this Winter.jpg needs to be placed? In which folder?
Where my .class files are?
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");
Re: Adding image to Java Application
thanks oceanebelle but i think ill make an applet on server side :D
Its easier this way.
Re: Adding image to Java Application
Quote:
Originally Posted by Dungeon Keeper
thanks oceanebelle but i think ill make an applet on server side :D
Its easier this way.
Sorry to disappoint you but Applets are all client-side
Re: Adding image to Java Application
Yeah i know but its different if applet is on user pc or on server pc :D
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
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! :wave:
Re: [RESOLVED] Adding image to Java Application