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



Home Answers Viewqa Swing-AWT Image Selection

Have Programming Question? Ask it here!
 
 
 


Sandeep Goel
Image Selection
1 Answer(s)      6 years and 3 months ago
Posted in : Swing AWT



Advertisement
View Answers

May 27, 2008 at 3:23 PM


Hi friend,

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;

public class DisplayImage extends JFrame {
JLabel promptLabel;
JTextField prompt;
JButton button;
JFileChooser fileChooser;
JComboBox comboBox;
JButton saveButton;
public DisplayImage() {
super("Image Selection program");
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container con = getContentPane();
JPanel inputPanel = new JPanel();
promptLabel = new JLabel("Filename:");
inputPanel.add(promptLabel);
prompt = new JTextField(20);
inputPanel.add(prompt);
button = new JButton("Browse");
inputPanel.add(button);
con.add(inputPanel, BorderLayout.NORTH);

fileChooser = new JFileChooser();
button.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
if (selectedFile != null) {
prompt.setText(selectedFile.getAbsolutePath());
}
}
}
}
);

JPanel outputPanel = new JPanel();
String writerFormats[] = ImageIO.getWriterFormatNames();
ComboBoxModel comboBoxModel = new DefaultComboBoxModel(writerFormats);
comboBox = new JComboBox(comboBoxModel);
outputPanel.add(comboBox);
saveButton = new JButton("Save");
outputPanel.add(saveButton);
saveButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String name = prompt.getText();
File file = new File(name);
if(file.exists()) {
BufferedImage image = ImageIO.read(file.toURL());
if(image == null) {
System.err.println("Invalid input file format");
} else {
String selection = (String)comboBox.getSelectedItem();
String outputFilename = name + "." + selection;
File outputFile = new File(outputFilename);
boolean found = ImageIO.write(image,selection, outputFile);
if (found) {
JDialog window = new JDialog();
Container windowContent = window.getContentPane();
BufferedImage newImage = ImageIO.read(outputFile);
JLabel label = new JLabel(new ImageIcon(newImage));
JScrollPane pane = new JScrollPane(label);
windowContent.add(pane,BorderLayout.CENTER);
window.setSize(500, 500);
window.show();
} else {
System.err.println("Error saving");
}
}
} else {
System.err.println("file name not select!");
}
} catch (MalformedURLException mur) {
System.err.println("Select file name not found");
} catch (IOException ioe) {
System.err.println("Error reading file");
}
}
}
);

con.add(outputPanel, BorderLayout.SOUTH);

}
public static void main(String args[]){
System.out.println("Display image on new window after selecting!");
JFrame frame = new DisplayImage();
frame.setSize(500,300);
frame.show();
}
}
------------------------------------------------
Read for more informaton.

http://www.roseindia.net/java/


Related Tutorials/Questions & Answers:
image selection
image selection  hi my issue is : I have select dropdown list when I selected image it displays some default color having image I change the color... it redirect to error image page. can you tell how to solve this problem and where
Image Selection - Swing AWT
Image Selection  Hi, I need to provide the image selection facility...; JButton saveButton; public DisplayImage() { super("Image Selection program... click on any item, the image of that item should be selected as done in windows
Advertisements
Syntax for image selection Urgent - JSP-Servlet
Syntax for image selection Urgent  Respected Sir/Madam, I am using the following syntax to know whether radio button has been clicked or not: for(var i=0;i  Hi friend, now show the question no 2129 Here
Image Selection Reply Urgent.. - JSP-Servlet
Image Selection Reply Urgent..  Respected Sir/Madam, I am R.Ragavendran.. Thanks for yuor fast response.. Sir actually I will be much more convenient if you provide me with coding.. I dont know to work with images as i
Very urgent Image Selection - JSP-Servlet
Very urgent Image Selection  Respected Sir/Madam, I am R.Ragavendran.. If you are telling that your coding works fine, then can u plz tell me or send me the output of the following code asap? var imageURL
Image selection instead of radio button very urgent.. - JSP-Servlet
Image selection instead of radio button very urgent..  Respected Sir/Madam, I am R.Ragavendran.. Actually in the following using radio... successfully. But I need some icon or some pictorial selection instead
Selection based on other selection in jsp
Selection based on other selection in jsp  I am trying to create a jsp page. Where I am having a select list containing category name and for each... selection on same jsp page such that when someone select a category only the products
highlight uitableviewcell on selection
the UITableViewCell on selection in my application.   UITableViewCell... highlight it or use the default selection for the cell in UITableView. Also you can disable the the stye by setting StyleNone to cell selection. But in case
insert multiple selection - Java
insert multiple selection - Java  how to insert multiple selection values from html into database using servlets
changing selection color of <button>
changing selection color of   dear all, i have loaded image in border less button tag when button is selected with tab key i get brown color rectangle around image. how do i change color of that rectangle from brown to white
interrelated two selection box
interrelated two selection box  hi i need two selection box .in 1 box all designation like manager, ceo etc , onclick on manager i should get list of managers names in second selection box.. like wise so on. from database
Help With Costructing Selection sort?
Help With Costructing Selection sort?  Using a selection sort, for each entry in the array, display the original index of the first dimension... in advance!   Please visit the following link: Java Selection Sort
Selection Using JoptionPane
Selection Using JoptionPane  Help, can someone provide me the code using JOptionPane for the following:- Part A 1) Prompt user to make 3 selection... Modify the above application so that if user makes a selection that the user has
Selection Sort
(...). Like all simple sorts, selection sort is implemented with two nested loops. Simple selection sort The basic idea is to look at each...] = temp; } } } } More efficient selection sort
checkbox selection in jsp
checkbox selection in jsp  hey guys i am working on a web based project using jsp. In my project i am having 9 check boxes in 3 rows in the same form. I want to select i check box from each row and also i want to avoid many
Displaying files on selection of date.
Displaying files on selection of date.  Hi, I am developing a GUI, where i select from and to date. On selection of from and to date the GUI should show the particular txt files of the selected date. I want the java logic
selection box linked with textarea
selection box linked with textarea    function get_val(tot_val1) { document.getElementById('TextBox1').value = tot_val1; alert(tot_val1... detals i have in db with all fields .. like wise i have names in selection box sham
Selection With Ajax and JSP
Selection With Ajax and JSP  I am working at a jsp page using ajax for country , state, city selection. so if he select country it will populate the state and city selection (both). After selecting country if he select city
else if (selection = * 'M'); - Java Beginners
else if (selection = * 'M');  I am trying to get 2 numbers 2... if (selection = * 'M'); ^ this is my program - what am i...; System.out.print("Enter A(dd), S(ubtract), M(ultiply):"); selection = (char
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
single selection of chechbox among multiple selection when in a loop.
single selection of chechbox among multiple selection when in a loop.  i am using cmd prompt to run and execute the java pgm. here i need your help... but here am getting multiple selection(previous selected item also coming again
enable text box and label on selection
enable text box and label on selection  hello, Please tell me how to enable label and text box on selection of drop down list box. in drop down list box all values come from database. please reply
JTable - Cell selection - Swing AWT
(ListSelectionModel.SINGLE_SELECTION); JScrollPane spane = new JScrollPane(table
Selection Sort in Java
Selection sort in Java is used to sort the unsorted values in an array. In selection sorting algorithm, the minimum value in an array is swapped... position. This procedure is repeated till the array is sorted completely. Selection
Selection Sort In Java
Selection Sort In Java      ... are going to sort the values of an array  using selection sort.In selection sorting.... Sort the remaining  values by using same steps. Selection sort 
Program Arrow selection Most Urgent - JSP-Servlet
Program Arrow selection Most Urgent  Respected Sir/Madam, I am R.Ragavendran.. I got your coding which is highly appreciable.. As per my requiremennt,there are image buttons for each row in the database.. But i am
Modifying a single row of database based on selection in jsp
Modifying a single row of database based on selection in jsp  Hi guys, i have a problem, I am Fetching the results from database and displaying in a row with s3everal columns, each row having a radio button and a value
Importance of Recruitment and Selection
the Recruitment and Selection is the basic significant factors which decides by Human Resource Department of the organization. Recruitment and Selection are one... be choose. On the other hand, Selection is the process where qualifications
Drop-down text selection in jsp/html
Drop-down text selection in jsp/html  Hi, I am trying to create JSP page where I have two drop-downs. There are two-sets of data - First set Categories- Movies, Books, Music and the Second set Genres- Action,Comedy,Romantic
Is there any inbuilt API in netbeans to know about selection in editor?
Is there any inbuilt API in netbeans to know about selection in editor?  Eclipse is having ISelction base interface for User Selection & it also provides concrete classes for that so as to know selection info in editor. how
How to create textbox on combo value selection using javacsript in jsp?
How to create textbox on combo value selection using javacsript in jsp?  dynamically create textbox on combo value selection. when select multiple values then create multiple textboxes
radio button selection should move the control to a text box that needs to be complete
radio button selection should move the control to a text box that needs to be complete  on selection of a radio button mouse should move to a particular text box that needs to be filled. How
Image Steganography
Image Steganography  SOURCE CODE FOR IMAGE STEGANOGRAPHY
image scrolling
image scrolling  A brief description of scrolling image
image format
image format  what are the different format available in image
image format
image format  what are the different format available in image
HOW TO DISPLAY ID IN TEXTBOX BASED ON COMBOBOX SELECTION IN A SAME PAGE
HOW TO DISPLAY ID IN TEXTBOX BASED ON COMBOBOX SELECTION IN A SAME PAGE  Dear sir, Am having one table called rolemaster. In that there are 2 fields Roleid and Role_name. and values are Roleid Role_name 1
Photoshop change a background image
) of the image which you want to add. Inverse: After selection, go to select menu.... Select Background: Again make selection of the image and go to select menu, click... Photoshop: change a background image   
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
Populate listbox according to selection value from another selectbox
Populate listbox according to selection value from another selectbox  hi... I am developing my webproject in which i have 3 campus and each campus has different different courses. In registration form i want two select boxes one
my table should be reseted to new value upon the selection of the combo box..
my table should be reseted to new value upon the selection of the combo box..  import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.sql.Connection
Advertisements
 

 

 

DMCA.com