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

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
ModuleNotFoundError: No module named 'browse'
ModuleNotFoundError: No module named 'browse'  Hi, My Python... 'browse' How to remove the ModuleNotFoundError: No module named 'browse'... to install padas library. You can install browse python with following command
ModuleNotFoundError: No module named 'browse'
ModuleNotFoundError: No module named 'browse'  Hi, My Python... 'browse' How to remove the ModuleNotFoundError: No module named 'browse'... to install padas library. You can install browse python with following command
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
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
image
image   Dear every body please help me how to add and retrive image and video into oracle 11g using jsp
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
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
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
ModuleNotFoundError: No module named 'git-browse'
ModuleNotFoundError: No module named 'git-browse'  Hi, My Python... 'git-browse' How to remove the ModuleNotFoundError: No module named 'git-browse' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'git-browse'
ModuleNotFoundError: No module named 'git-browse'  Hi, My Python... 'git-browse' How to remove the ModuleNotFoundError: No module named 'git-browse' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'git-browse'
ModuleNotFoundError: No module named 'git-browse'  Hi, My Python... 'git-browse' How to remove the ModuleNotFoundError: No module named 'git-browse' error? Thanks   Hi, In your python environment you
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
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
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 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
ModuleNotFoundError: No module named 'npm-browse-cli'
ModuleNotFoundError: No module named 'npm-browse-cli'  Hi, My... named 'npm-browse-cli' How to remove the ModuleNotFoundError: No module named 'npm-browse-cli' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'npmjs-browse-cli'
ModuleNotFoundError: No module named 'npmjs-browse-cli'  Hi, My... named 'npmjs-browse-cli' How to remove the ModuleNotFoundError: No module named 'npmjs-browse-cli' error? Thanks   Hi, In your
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
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
Version of com.box>box-android-browse-sdk dependency
List of Version of com.box>box-android-browse-sdk dependency
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
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
image scrolling
image scrolling  A brief description of scrolling image
Image Steganography
Image Steganography  SOURCE CODE FOR IMAGE STEGANOGRAPHY
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
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
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
image format
image format  what are the different format available in image

Ads