How Do I Upload an Image in Pardo
- Updated date Sep sixteen, 2019
- 70.6k
- 0
In this article, we are going to describe how to upload your epitome into a frame in Java.
Introduction
In this article, we are going to describe how to upload your epitome into a frame, and image choice with the help of a FileDailog. File choosers provide a GUI for navigating the file organisation and then either cull a file or directory from a list or enter the proper noun of a file or directory. To display a file chooser, you usually use the JFileDailog API to show a modal dialog containing the file chooser. Some other way to nowadays a file chooser is to add together an instance of JFileDailog to a container.
Note
If you want to start an unsigned Java™ Web application every bit a distributed form then you lot should utilize the services of JNLP instead of jFileChooser. The services FileOpenService and FileSaveService not only provide support for choosing files in a restricted environs merely also take intendance of actually opening and saving them. An example of using these services is in JWSFileChooserDemo. Documentation for using the JNLP API tin can exist found in the Java Spider web Start lesson.
FileDailog Class API Clarification
Constructor Details
- FileDialog(Dialog parent) This constructor is used to create a file dialog for loading a file. Here parent is the owner of the dialog
- FileDialog(Dialog parent, String championship)
This constructor is used to create a file dialog window with the specified title for loading a file. Here parent is the owner of the dialog and the second argument championship is the championship of the dialog; a null value will exist accustomed without causing a NullPointerException to exist thrown.
- FileDialog(Dialog parent, String title, int m)
This constructor is used to create a file dialog window with the specified championship for loading or saving a file. Hither the parent is the possessor of the dialog and the second argument title is the title of the dialog. And the third is the style of the dialog; either FileDialog.LOAD or FileDialog.Salvage.
Some Useful Methods
- void addNotify()
Creates the file dialog's peer. -
- String getDirectory()
Gets the directory of this file dialog. - Cord getFile()
Gets the selected file of this file dialog. - FilenameFilter getFilenameFilter()
Determines this file dialog'southward filename filter. - File[] getFiles()
Returns files that the user selects. - int getMode()
Indicates whether this file dialog box is for loading from a file or for saving to a file. - boolean isMultipleMode()
Returns whether the file dialog allows the multiple file pick. - protected String paramString()
Returns a string representing the state of this FileDialog window. - void setDirectory(Cord dir)
Sets the directory of this file dialog window to be the specified directory. - void setFile(String file)
Sets the selected file for this file dialog window to exist the specified file. - void setFilenameFilter(FilenameFilter filter)
Sets the filename filter for this file dialog window to the specified filter. - void setMode(int fashion)
Sets the manner of the file dialog. - void setMultipleMode(boolean enable)
Enables or disables multiple file selection for the file dialog.
Example
- import coffee.awt.*;
- import coffee.awt.event.*;
- import java.awt.epitome.*;
- import javax.swing.*;
- import coffee.awt.Frame;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- class imageLoad extends Sail
- {
- Image img;
- public imageLoad(Image img)
- {
- this .img = img;
- }
- public void paint(Graphics g)
- {
- if (img != null )
- {
- g.drawImage(img,100 , 400 , 400 , this );
- }
- }
- public void setImage(Epitome img)
- {
- this .img = img;
- }
- }
- public course ImagesLoading implements ActionListener
- {
- JFrame fr =new JFrame( "Image loading programme Using awt" );
- Label Label1 =new Label( "Choose your epitome" );
- Button Button1 =new Button( "select" );
- Epitome Image1;
- imageLoad Canvas1;
- FileDialog fd =new FileDialog(fr, "Open" , FileDialog.LOAD);
- void initialize()
- {
- fr.setSize(500 , 500 );
- fr.setLocation(200 , 200 );
- fr.setBackground(Colour.lightGray);
- fr.setLayout(new FlowLayout());
- fr.add(Label1);
- fr.add together(Button1);
- fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Button1.addActionListener(this );
- Canvas1 =new imageLoad( null );
- Canvas1.setSize(g , 1000 );
- fr.add together(Canvas1);
- fr.prove();
- }
- void imageload()
- {
- fd.show();
- if (fd.getFile() == zero )
- {
- Label1.setText("You have not select" );
- }else
- {
- String d = (fd.getDirectory() + fd.getFile());
- Toolkit toolkit = Toolkit.getDefaultToolkit();
- Image1 = toolkit.getImage(d);
- Canvas1.setImage(Image1);
- Canvas1.repaint();
- }
- }
- public void windowClosing(WindowEvent due east)
- {
- System.get out(0 );
- }
- public void windowActivated(WindowEvent e)
- {
- }
- public void windowClosed(WindowEvent e)
- {
- }
- public void windowDeactivated(WindowEvent due east)
- {
- }
- public void windowDeiconified(WindowEvent e)
- {
- }
- public void windowIconified(WindowEvent eastward)
- {
- }
- public void windowOpened(WindowEvent e)
- {
- }
- public void actionPerformed(ActionEvent result)
- {
- Button b = (Push) event.getSource();
- if (b == Button1)
- {
- imageload();
- }
- }
- public static void primary(String args[])
- {
- ImagesLoading a =new ImagesLoading();
- a.initialize();
- }
- }
Output
cmd output
Initial Output
When yous click on the select button the following window will appear.
Later on browsing a selected image the following will be shown:
Resources
- Upload an Prototype and an Sound file using C#
- How to Upload Images to Databases or How to shop images to database
- Multiple Image Upload in ASP.Net
- Image Uploading in PHP
- JavaScript part: To upload multiple image
Source: https://www.c-sharpcorner.com/UploadFile/433c33/image-uploading-in-java/
0 Response to "How Do I Upload an Image in Pardo"
إرسال تعليق