⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageprocframe.java

📁 java灵感设计
💻 JAVA
字号:
package imageproc;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;/** * <p>Title:  ImageProc Demo</p> * <p>Description: This is a ImageProc Demo</p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: D6-125</p> * @author liujun * @version 1.0 */public class ImageProcFrame extends JFrame {  JPanel contentPane;  BorderLayout borderLayout1 = new BorderLayout();  //声明自己创建的Panel1类变量  Panel1 myPanel1 = new Panel1();  JPanel jPanel1 = new JPanel();  JButton jButton1 = new JButton();  JPanel jPanel2 = new JPanel();  JRadioButton jRadioButton1 = new JRadioButton();  JRadioButton jRadioButton2 = new JRadioButton();  JRadioButton jRadioButton3 = new JRadioButton();  JRadioButton jRadioButton4 = new JRadioButton();  ButtonGroup buttonGroup1 = new ButtonGroup();  JRadioButton jRadioButton5 = new JRadioButton();  //Construct the frame  public ImageProcFrame() {    enableEvents(AWTEvent.WINDOW_EVENT_MASK);    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  //Component initialization  private void jbInit() throws Exception  {    //setIconImage(Toolkit.getDefaultToolkit().createImage(ImageProcFrame.class.getResource("[Your Icon]")));    contentPane = (JPanel) this.getContentPane();    contentPane.setLayout(borderLayout1);    this.setSize(new Dimension(445, 300));    this.setTitle("ImageProc Frame Demo");    jButton1.setMnemonic('0');    jButton1.setText("打开一个文件");    jButton1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jButton1_actinPerformed(e);      }    });    jRadioButton1.setText("模糊处理");    jRadioButton1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jRadioButton1_actionPerformed(e);      }    });    jRadioButton2.setText("变亮操作");    jRadioButton2.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jRadioButton2_actionPerformed(e);      }    });    jRadioButton3.setText("变成灰度图");    jRadioButton3.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jRadioButton3_actionPerformed(e);      }    });    jRadioButton4.setText("边界检测");    jRadioButton4.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jRadioButton4_actionPerformed(e);      }    });    jRadioButton5.setText("原始图形");    jRadioButton5.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jRadioButton5_actionPerformed(e);      }    });    contentPane.add(jPanel1, BorderLayout.NORTH);    jPanel1.add(jButton1, null);    contentPane.add(jPanel2,  BorderLayout.SOUTH);    jPanel2.add(jRadioButton1, null);    jPanel2.add(jRadioButton2, null);    jPanel2.add(jRadioButton3, null);    jPanel2.add(jRadioButton4, null);    jPanel2.add(jRadioButton5, null);    buttonGroup1.add(jRadioButton1);    buttonGroup1.add(jRadioButton2);    buttonGroup1.add(jRadioButton3);    buttonGroup1.add(jRadioButton4);    buttonGroup1.add(jRadioButton5);    //添加Panel1类变量到界面    contentPane.add(myPanel1, BorderLayout.CENTER);  }  //Overridden so we can exit when window is closed  protected void processWindowEvent(WindowEvent e) {    super.processWindowEvent(e);    if (e.getID() == WindowEvent.WINDOW_CLOSING) {      System.exit(0);    }  }  void jButton1_actinPerformed(ActionEvent e) {     //用于选择图像文件       JFileChooser chooser = new JFileChooser();         chooser.setCurrentDirectory(new File("."));        //设置图像文件过滤器对象         chooser.setFileFilter(new            javax.swing.filechooser.FileFilter()            {  public boolean accept(File f)               {  String name = f.getName().toLowerCase();                  return name.endsWith(".gif")                     || name.endsWith(".jpg")                     || name.endsWith(".jpeg")                     || f.isDirectory();               }               public String getDescription()               {  return "Image files";               }            });         //显示文件选择器         int r = chooser.showOpenDialog(this);         if(r == JFileChooser.APPROVE_OPTION)         {  String name //得到文件名               = chooser.getSelectedFile().getAbsolutePath();            //调出图像并显示            myPanel1.loadImage(name);         }   change();  }  void jRadioButton1_actionPerformed(ActionEvent e) {   change();  }  void jRadioButton2_actionPerformed(ActionEvent e) {   change();  }  void jRadioButton3_actionPerformed(ActionEvent e) {   change();  }  void jRadioButton4_actionPerformed(ActionEvent e) {   change();  }  void jRadioButton5_actionPerformed(ActionEvent e) {  change();  }  void change(){   if(jRadioButton1.isSelected()){    myPanel1.blur();   }else if(jRadioButton2.isSelected()){   myPanel1.brighten();   }else if(jRadioButton3.isSelected()){   myPanel1.toGray();   }else if(jRadioButton4.isSelected()){   myPanel1.edgeDetect();   }else  if(jRadioButton5.isSelected()){   myPanel1.restore();    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -