Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


pradeep joshi
browse image
1 Answer(s)      3 years and 3 months ago
Posted in : Java Beginners


how to browse the image in image box by browse button and save image in database by save button by swing


Advertisement
View Answers

May 9, 2011 at 4:01 PM


import java.sql.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.image.*;
import java.awt.event.*;

public class UploadImage extends JFrame {
Image img;
JTextField text=new JTextField(20);
JButton browse,save;
JPanel p=new JPanel(new GridLayout(1,2));
JLabel label=new JLabel();
File file = null;
String path="";
public UploadImage() {

browse = new JButton("Upload");
save = new JButton("Save");
text.setBounds(20,20,140,20);
browse.setBounds(160,20,100,20);
label.setBounds(20,40,260,20);
save.setBounds(250,20,100,20);
add(p);
setSize(600,500);
add(text);
add(browse);
add(save);

add(label);
setVisible(true);

browse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.addChoosableFileFilter(new ImageFileFilter());
int returnVal = chooser.showOpenDialog(null);

if(returnVal == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile();
 path=file.getPath();
ImageIcon icon=new ImageIcon(path);
label.setIcon(icon);
text.setText(path);

repaint();
}
}
});
save.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
        try{
        File f=new File(path);
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.10.13:3306/rose", "root", "root");
PreparedStatement psmnt = connection.prepareStatement("insert into images(image) values(?)");
FileInputStream fis = new FileInputStream(f);
psmnt.setBinaryStream(1, (InputStream)fis, (int)(f.length()));
int s = psmnt.executeUpdate();
JOptionPane.showMessageDialog(null,"Inserted successfully!");
    }
    catch(Exception ex){
        System.out.print(ex);
    }
    }

});
}

public static void main(String[] args) {
 new UploadImage();
}

}
class ImageFileFilter extends javax.swing.filechooser.FileFilter {
public boolean accept(File file) {
if (file.isDirectory()) return false;
String name = file.getName().toLowerCase();
return (name.endsWith(".jpg") || name.endsWith(".png")|| name.endsWith(".gif"));
}
public String getDescription() { return "Images (*.gif,*.bmp, *.jpg, *.png )"; }
}


Related Tutorials/Questions & Answers:
browse image
browse image  how to browse the image in image box by browse button and save image in database by save button by swing   import java.sql.... java.awt.image.*; import java.awt.event.*; public class UploadImage extends JFrame { Image
browse image
browse image  how to browse the image in image box by browse button and save image in database by save button by swing   import java.sql.... java.awt.image.*; import java.awt.event.*; public class UploadImage extends JFrame { Image
Advertisements
Browse an image
Browse an image  hi................ i want to browse an image from... java.awt.event.*; public class UploadImage extends JFrame { Image img; JTextField text=new JTextField(20); JButton browse,save; JPanel p=new JPanel(new
Using a image for Browse button instead of normal html Browse button for Uploading files from a JSP - JSP-Servlet
Using a image for Browse button instead of normal html Browse button for Uploading files from a JSP  I am using the following code snippet.... Is it not possible to use a image instead of normal html Browse button for uploading files
inserting image in mysql database using browse button in servlets
inserting image in mysql database using browse button in servlets  Hi,I want to insert a image in mysql database using browse button. and, i want to display all inserted images in a form from there i want to download the image
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
BROWSE BUTTON CODE
BROWSE BUTTON CODE  HOW TO STORE THE FILE BROWSE TO THE DATABASE   JSP File Upload 1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display file upload form to the user</TITLE>
BROWSE BUTTON CODE
BROWSE BUTTON CODE  HOW TO STORE THE FILE BROWSE TO THE DATABASE   JSP File Upload 1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display file upload form to the user</TITLE>
browse a file with java - Development process
browse a file with java  I want to count the number of white line and comment line in a file type with sql with java
Upload Image using Servlet
Upload Image using Servlet       This application illustrates how to upload an image using servlet. In this example program a form is displayed to user, where user can browse
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings.  Hi friend, import... () { this.setLayout(null); button = new JButton("browse
how to browse folder and directory in jsp
how to browse folder and directory in jsp  how to browse folder and directory in my jsp page.i have done my coding part for browsing directory but dont know how to get files after that.and also i want to show limited directories
image
image  how to add the image in servlet code
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
how to browse the general files which are in system using java? - Java Beginners
how to browse the general files which are in system using java?  how to browse the general files which are in system using java? its just like in ms... and it shows all the word document files, like that i want open all image files using
browse and submit the excel sheet into mysql as a table
browse and submit the excel sheet into mysql as a table  sir, i want to browse and after clicking a submit button, the data in the excel sheet should be stored in the mysql5.0 as a table
Image processing
Image processing  i want a browsing program in java in which we hv a small img and we hv to browse this img on a big image so that we can find the similar type of image in big img
Java file browse
Java file browse In this section, you will learn how to browse a file and allows the user to choose a file. Description of code GUI provide File choosers for navigating the file system, and then provide the utility to choose either
Browse Button Enlarge Field - Development process
Browse Button Enlarge Field  How can I enlarge the browse text field... the browse button and selecting my document, only about 20 characters... data in the field.   Hi friend, Code for Browse the file
Text Editor Image upload
Text Editor Image upload   how to browse an image from text editor instead of giving url of particular image using javascript
Browse Excel File Problem - Development process
Browse Excel File Problem  I am using a web application,in which i have to browse an excel file columns. It is working in my system. But if i access... displayed when i browse the file. What is the problem?  Hi Friend
How to browse excel file and stored the contents into the database using jsp/servlet?
How to browse excel file and stored the contents into the database using jsp/servlet?  Hi.. I want to browse excel file and stored the file data into the My-sql database using jsp/servlet
Export data in excel sheet via Browse and upload button into mysql database
Export data in excel sheet via Browse and upload button into mysql database  how to create a Browse & Upload Buttons and then save the information from it in mysql database's Table Am using struts2,hibernate for making
Image preview - JSP-Servlet
Image preview  How to show the preview of the image when we select the image through browse button in JSP page before storing it in the application... select the image using the file type button i want to dynamically show
image insert - Java Beginners
image insert  i browsed the image by clicking d browse button.if i press submit button means d image automatically stored in db.then i have 2 retrieve d image separately...................... Untitled Document
How to browse and upload the file in same page using jsp.
How to browse and upload the file in same page using jsp.  Hi, I am doing a project and i want to browse and upload the file in same page inside... allow the user to browse a file to upload. The file is then uploaded to server
How to browse and upload the file in same page using jsp.
How to browse and upload the file in same page using jsp.  Hi Sir, I am doing a project in jsp servlets and i want to browse and upload.... The given code allow the user to browse a file to upload. The file is then uploaded
Image Steganography
Image Steganography  SOURCE CODE FOR IMAGE STEGANOGRAPHY
image scrolling
image scrolling  A brief description of scrolling image
upload image and fields.....fields is id name.....
upload image and fields.....fields is id name.....  Hi this is sreenu my problam is capcharing data to the servler thi is my frame Id: Name: browse:Image are file
upload image and fields.....fields is id name.....
upload image and fields.....fields is id name.....  Get Data using Java Servlet The frame takes following input.. Id: Name: browse:Image are file
image format
image format  what are the different format available in image
image format
image format  what are the different format available in image
Regarding Image in Swings
Regarding Image in Swings  Hi, I have some requireemnt like when i click on the button in frame,it wil display the image.....plz do the needful...; JButton browse; JLabel label; File file = null; public DisplayImage() { f = new
To scan a image encode that image in j2me
To scan a image encode that image in j2me  Hai team i am new man of j2me i have doubt to scan a image and encode the image in j2me... Please clarify that doubt... Thanks in Advance... Kumar
image scrambling
image scrambling  Hi frinds : i want to read image and scrambling it then saved using java any help please
Image_creation
Image_creation  how to create an image from a set of pixel values stored in array - in java
image in database
image in database  how to set image in database and retrieve it using servlet(java)in msaccess
 

 

 

DMCA.com