中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

簡單的 java圖片瀏覽器示例

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageFilter;
import java.awt.image.ImageProducer;
import java.io.File;
import javax.swing.*;
public class vicePic implements ActionListener {
    JLabel imgLable;
    JFrame mainJframe;
    Container con;
    JTextField fileFiled;
    JButton openBtn,cutBtn;
    JPanel pane;
    JScrollPane spanel;
    ImageIcon img;
    public vicePic(){
        mainJframe=new JFrame("圖形顯示比例");
        con=mainJframe.getContentPane();
        pane=new JPanel();
        pane.setLayout(new FlowLayout());
        openBtn=new JButton("打開文件");
        openBtn.addActionListener(this);
        cutBtn=new JButton("剪切圖片");
        cutBtn.addActionListener(this);
        fileFiled=new JTextField();
        fileFiled.setColumns(20);
        pane.add(fileFiled);
        pane.add(openBtn);
        pane.add(cutBtn);
        imgLable =new JLabel();
        spanel=new JScrollPane(imgLable);
        con.add(pane,BorderLayout.NORTH);
        con.add(spanel,BorderLayout.CENTER);
        mainJframe.setSize(800, 800);
        mainJframe.setVisible(true);
        mainJframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        }
    @Override
    public void actionPerformed(ActionEvent e) {
        String cmd=e.getActionCommand();
        ImageFilter cropFilter;
        Image croppedImage;
        ImageProducer produer;
        if(cmd.equals("打開文件")){
        try{
            JFileChooser chooser=new JFileChooser();
            if(chooser.showOpenDialog(mainJframe)==JFileChooser.APPROVE_OPTION){
                File tempfile=chooser.getSelectedFile();
                fileFiled.setText(tempfile.toString());
                img=new ImageIcon(fileFiled.getText());
                imgLable.setIcon(img);      
                }http://www.huiyi8.com/jiaoben/
        }catch(Exception el){
            JOptionPane.showMessageDialog(mainJframe, "圖品無法顯示");

        }
        }
        if(cmd.equals("剪切圖片")){
            cropFilter=new CropImageFilter(100, 100, 200, 200);
            produer=new FilteredImageSource(img.getImage().getSource(), cropFilter);
            croppedImage=Toolkit.getDefaultToolkit().createImage(produer);
            imgLable.setIcon(new ImageIcon(croppedImage));
            }
    }
    public static void main(String[] args){
        new vicePic();
    }

}

標簽: seo

版權申明:本站文章部分自網(wǎng)絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:JavaScript實現(xiàn)的隨機色標簽云

下一篇:Java創(chuàng)建縮略圖的方法