java 打开图片_java 程序肿么打开一张图片?

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 ; } }}

取消

评论

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 ; } }} 取消 评论
经验分享 程序员 微信小程序 职场和发展