当前位置: 技术问答>java相关
谁能给一段java写的生成缩略图的代码?
来源: 互联网 发布时间:2017-03-09
本文导语: 谢了!急需! | 稍作处理即可满足你的要求: import java.awt.*; import java.awt.event.*; import java.beans.*; import java.io.File; import javax.swing.*; public class JFileChooserTest extends JFrame { JFileChooser chooser =...
谢了!急需!
|
稍作处理即可满足你的要求:
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.io.File;
import javax.swing.*;
public class JFileChooserTest extends JFrame
{
JFileChooser chooser = new JFileChooser();
JButton button = new JButton("show file chooser...");
ImagePreviewer previewer = new ImagePreviewer();
PreviewPanel previewPanel = new PreviewPanel();
class PreviewPanel extends JPanel
{
public PreviewPanel()
{
JLabel label = new JLabel("Image Previewer",SwingConstants.CENTER);
setPreferredSize(new Dimension(150,0));
setBorder(BorderFactory.createEtchedBorder());
setLayout(new BorderLayout());
label.setBorder(BorderFactory.createEtchedBorder());
add(label,BorderLayout.NORTH);
add(previewer,BorderLayout.CENTER);
}
}
public JFileChooserTest()
{
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
contentPane.add(button);
chooser.setAccessory(previewPanel);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int state = chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
String s = "CANCELED";
if (file != null && state == JFileChooser.APPROVE_OPTION)
{
s = "File Selected:" + file.getPath();
}
JOptionPane.showMessageDialog(null,s);
}
});
chooser.addPropertyChangeListener(new PropertyChangeListener()
{
public void propertyChange(PropertyChangeEvent e)
{
if (e.getPropertyName().equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY))
{
File f = (File) e.getNewValue();
String s = f.getPath(),suffix = null;
int i = s.lastIndexOf('.');
if (i>0 && i
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.io.File;
import javax.swing.*;
public class JFileChooserTest extends JFrame
{
JFileChooser chooser = new JFileChooser();
JButton button = new JButton("show file chooser...");
ImagePreviewer previewer = new ImagePreviewer();
PreviewPanel previewPanel = new PreviewPanel();
class PreviewPanel extends JPanel
{
public PreviewPanel()
{
JLabel label = new JLabel("Image Previewer",SwingConstants.CENTER);
setPreferredSize(new Dimension(150,0));
setBorder(BorderFactory.createEtchedBorder());
setLayout(new BorderLayout());
label.setBorder(BorderFactory.createEtchedBorder());
add(label,BorderLayout.NORTH);
add(previewer,BorderLayout.CENTER);
}
}
public JFileChooserTest()
{
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
contentPane.add(button);
chooser.setAccessory(previewPanel);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int state = chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
String s = "CANCELED";
if (file != null && state == JFileChooser.APPROVE_OPTION)
{
s = "File Selected:" + file.getPath();
}
JOptionPane.showMessageDialog(null,s);
}
});
chooser.addPropertyChangeListener(new PropertyChangeListener()
{
public void propertyChange(PropertyChangeEvent e)
{
if (e.getPropertyName().equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY))
{
File f = (File) e.getNewValue();
String s = f.getPath(),suffix = null;
int i = s.lastIndexOf('.');
if (i>0 && i