package com.open.cc; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class CutImage extends JFrame implements ActionListener{ /**实现界面输入输出图 * */ private static final long serialVersionUID = 1L; private JTextField showpath; private JButton sure; private JLabel showpicture; FileDialog fdg; public static void main(String[] args){ new CutImage().setVisible(true); } public CutImage(){ super(); setTitle("CutImage"); //setSize(500,450); setLocationRelativeTo(null); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); showpath = new JTextField(40); sure=new JButton(); sure.addActionListener(this); sure.setText("OPEN"); JPanel p1=new JPanel(); p1.add(showpath); p1.add(sure); getContentPane().add(p1,BorderLayout.NORTH); showpicture=new JLabel(); fdg=new FileDialog(this); pack(); } public void actionPerformed(ActionEvent e){ if(e.getSource()==sure){ fdg.setMode(FileDialog.LOAD); } fdg.setVisible(true); String str = fdg.getFile().substring((fdg.getFile().length()-3),fdg.getFile().length()); if(str.equals("png")||str.equals("jpg")){ showpath.setText(fdg.getDirectory()+fdg.getFile()); showpicture.setIcon(new ImageIcon(showpath.getText())); getContentPane().add(showpicture,BorderLayout.SOUTH); pack(); }else{ JOptionPane.showMessageDialog(null,"Select Wrong file!"); return ; } } }