Image Retrieval Program

Source: Internet
Author: User

/*
@ The purpose of this program is to filter files through the file filter.
@ Author: Li hongliang
*/

Import java. awt. event .*;
Import java. io .*;
Import javax. swing .*;
Import java. util .*;
Import javax. swing. event .*;
Import java. awt .*;
Import javax. swing. filechooser. FileFilter;

Public class CheckImageDemo extends JFrame {
Private JMenu menu, helpmenu;
Private JMenuItem openFile, exititem, helpitem;
Private JLabel label, label1;
Private JScrollPane jscrollPane;
Private JMenuBar menuBar;
Private JFileChooser fileChooser;

Public CheckImageDemo (){
Super ("retrieving images ");
This. addWindowListener (new WindowAdapter (){
Public void windowClosing (WindowEvent ev ){
System. exit (0 );
}
});
MenuBar = new JMenuBar ();
Menu = new JMenu ("file ");
OpenFile = new JMenuItem ("open ");
Exititem = new JMenuItem ("quit ");
SetJMenuBar (menuBar );
MenuBar. add (menu );
Menu. add (openFile );
Menu. add (exititem );
/*************************************** ****************************************
File "exit" listening event
**************************************** ***************************************/
Exititem. addActionListener (new ActionListener (){
Public void actionreceivmed (ActionEvent e ){
System. exit (0 );
}
});
Helpmenu = new JMenu ("about ");
Helpitem = new JMenuItem ("about image retrieval ");
Helpmenu. add (helpitem );
MenuBar. add (helpmenu );
/*************************************** ****************************************
"About" monitoring events
**************************************** ***************************************/
Helpitem. addActionListener (new ActionListener (){
Public void actionreceivmed (ActionEvent e ){
String str = "welcome to use this program! "+"/N "+
"The copyright of the program is owned by the author." + "/n" +
"Author: Li hongliang Update: 2008-04-03" + "/n" +
"For more information, visit: http://lhl54861287.qyun.net ";
JOptionPane. showMessageDialog (null, str, "about retrieving images", JOptionPane. INFORMATION_MESSAGE );
}
});
Label = new JLabel ("", SwingConstants. CENTER );
Label1 = new JLabel ("", SwingConstants. CENTER );
Label1.setText ("Image Retrieval Center ");
Label. setIcon (new ImageIcon ("1.gif "));
JscrollPane = new JScrollPane ();
JscrollPane. getViewport (). add (label );
GetContentPane (). setLayout (new BorderLayout ());
GetContentPane (). add (jscrollPane, BorderLayout. CENTER );
GetContentPane (). add (label1, BorderLayout. SOUTH );
FileChooser = new JFileChooser ();
JFileFilter filter = new JFileFilter ();
Filter. addType ("jpg ");
Filter. addType ("gif ");
Filter. setDescription ("IMG archives ");
FileChooser. addChoosableFileFilter (filter );
/*************************************** ****************************************
Listener for file "open"
**************************************** ***************************************/
OpenFile. addActionListener (new ActionListener (){
Public void actionreceivmed (ActionEvent e ){
Int r = fileChooser. showOpenDialog (null );
If (r = JFileChooser. APPROVE_OPTION ){
String pathname = fileChooser. getSelectedFile (). getPath ();
Label1.setText ("The path of the image you open is:" + pathname );
Label. setIcon (new ImageIcon (pathname ));
}
}
});
}

Class JFileFilter extends FileFilter {
Protected String description;
Protected ArrayList arraylist = new ArrayList ();

Public void addType (String s ){
Arraylist. add (s );
}

Public void setDescription (String s ){
Description = s;
}

Public String getDescription (){
Return description;
}

Public boolean accept (File f ){
If (f. isDirectory ()){
Return true;
} Else if (f. isFile ()){
Iterator it = arraylist. iterator ();
While (it. hasnext ()){
If (F. getname (). endswith (string) it. Next () return true;
}
}
Return false;
}
}

Public static void main (string ARGs []) {
Checkimagedemo frame = new checkimagedemo ();
Frame. setsize (800,450 );
Dimension screensize = toolkit. getdefatooltoolkit (). getscreensize ();
Dimension framesize = frame. getsize ();
Frame. setlocation (screensize. width-frameSize.width)/2, (screensize. height-frameSize.height)/2 );
Frame. setvisible (true );
}
}

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.