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

  1. import  coffee.awt.*;
  2. import  coffee.awt.event.*;
  3. import  java.awt.epitome.*;
  4. import  javax.swing.*;
  5. import  coffee.awt.Frame;
  6. import  java.awt.event.WindowAdapter;
  7. import  java.awt.event.WindowEvent;
  8. class  imageLoad extends  Sail
  9. {
  10.  Image img;
  11. public  imageLoad(Image img)
  12.  {
  13. this .img = img;
  14.  }
  15. public void  paint(Graphics g)
  16.  {
  17. if  (img != null )
  18.   {
  19.    g.drawImage(img,100 , 400 , 400 , this );
  20.   }
  21.  }
  22. public void  setImage(Epitome img)
  23.  {
  24. this .img = img;
  25.  }
  26. }
  27. public course  ImagesLoading implements  ActionListener
  28. {
  29.  JFrame fr =new  JFrame( "Image loading programme Using awt" );
  30.  Label Label1 =new  Label( "Choose your epitome" );
  31.  Button Button1 =new  Button( "select" );
  32.  Epitome Image1;
  33.  imageLoad Canvas1;
  34.  FileDialog fd =new  FileDialog(fr, "Open" , FileDialog.LOAD);
  35. void  initialize()
  36.  {
  37.   fr.setSize(500 , 500 );
  38.   fr.setLocation(200 , 200 );
  39.   fr.setBackground(Colour.lightGray);
  40.   fr.setLayout(new  FlowLayout());
  41.   fr.add(Label1);
  42.   fr.add together(Button1);
  43.   fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  44.   Button1.addActionListener(this );
  45.   Canvas1 =new  imageLoad( null );
  46.   Canvas1.setSize(g , 1000 );
  47.   fr.add together(Canvas1);
  48.   fr.prove();
  49.  }
  50. void  imageload()
  51.  {
  52.   fd.show();
  53. if  (fd.getFile() == zero )
  54.   {
  55.    Label1.setText("You have not select" );
  56.   }else
  57.   {
  58.    String d = (fd.getDirectory() + fd.getFile());
  59.    Toolkit toolkit = Toolkit.getDefaultToolkit();
  60.    Image1 = toolkit.getImage(d);
  61.    Canvas1.setImage(Image1);
  62.    Canvas1.repaint();
  63.   }
  64.  }
  65. public void  windowClosing(WindowEvent due east)
  66.  {
  67.   System.get out(0 );
  68.  }
  69. public void  windowActivated(WindowEvent e)
  70.  {
  71.  }
  72. public void  windowClosed(WindowEvent e)
  73.  {
  74.  }
  75. public void  windowDeactivated(WindowEvent due east)
  76.  {
  77.  }
  78. public void  windowDeiconified(WindowEvent e)
  79.  {
  80.  }
  81. public void  windowIconified(WindowEvent eastward)
  82.  {
  83.  }
  84. public void  windowOpened(WindowEvent e)
  85.  {
  86.  }
  87. public void  actionPerformed(ActionEvent result)
  88.  {
  89.   Button b = (Push) event.getSource();
  90. if  (b == Button1)
  91.   {
  92.    imageload();
  93.   }
  94.  }
  95. public static void  primary(String args[])
  96.  {
  97.   ImagesLoading a =new  ImagesLoading();
  98.   a.initialize();
  99.  }
  100. }

Output

cmd output

tdcmd.gif

Initial Output

td1.gif

When yous click on the select button the following window will appear.

img2.png

Later on browsing a selected image the following will be shown:

td2.gif

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

hickssinglaid.blogspot.com

Source: https://www.c-sharpcorner.com/UploadFile/433c33/image-uploading-in-java/

0 Response to "How Do I Upload an Image in Pardo"

إرسال تعليق

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel