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 selectionimage 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 AWTImage 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-ServletSyntax 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-ServletImage 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-ServletVery 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
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
Selection based on other selection in jspSelection 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
imageimage how to add the
image in servlet code
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
ImageImage how to insert
image in xsl without using xml. the
image was displayed in pdf..Please help me
ImageImage how to insert
image in xsl without using xml. the
image was displayed in pdf..Please help me
ImageImage how to insert
image in xsl without using xml. the
image was displayed in pdf..Please help me
ModuleNotFoundError: No module named 'selection'ModuleNotFoundError: No module named '
selection' Hi,
My Python... '
selection'
How to remove the ModuleNotFoundError: No module named '
selection' error?
Thanks
Hi,
In your python environment you
image image Dear every body please help me how to add and retrive
image and video into oracle 11g using jsp
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
interrelated two selection boxinterrelated 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
Selection Using JoptionPaneSelection 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
checkbox selection in jspcheckbox
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
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
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 With Ajax and JSPSelection 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 Beginnerselse 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
enable text box and label on selectionenable 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
Selection Sort in JavaSelection 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-ServletProgram 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