📄 appletdemo.java~13~
字号:
package multimediademo;import java.awt.*;import java.awt.event.*;import java.applet.*;import java.net.*;import java.awt.image.*;import multimediademo.ImageFilter;import javax.swing.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class AppletDemo extends Applet implements Runnable{ private boolean isStandalone = false; //变量申明 private URL m_imageURL; //图像的URL private String m_imageName; //图像文件的名称 Image sourceImage,filteredImage; //图像类变量 ImageFilter imageFilter; //申明一个图像过滤器 MediaTracker tracker; //定义媒体跟踪器 Thread thread = new Thread(); //定义一个空线程 //Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } //Construct the applet public AppletDemo() { } //重载的构造函数/* public AppletDemo(URL imageURL,String imageName){ m_imageURL = imageURL; m_imageName = imageName; }*/ //Initialize the applet public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { sourceImage = this.getImage(m_imageURL,m_imageName); filteredImage = sourceImage; ImageFilter imageFilter = new ImageFilter(); } //Get Applet information public String getAppletInfo() { return "Applet Information"; } //Get parameter info public String[][] getParameterInfo() { return null; } //定义paint函数 public void paint(Graphics g){ if(!tracker.checkAll(true)){ this.showStatus("Now,the images are loading..."); } else{ this.showStatus("Loading images is over"); g.drawImage(filteredImage,50,50,150,150,this); } } //线程开始函数 public void start(){ if(thread == null){ thread = new Thread(this,"DemoThread"); thread.start(); } } //Overriding stop function public void stop(){ if(thread != null){ thread.stop(); thread = null; } } //Overriding destroy function public void destroy(){ } //Overriding run function public void run(){ while(true){ imageFilter.pixelValueChange(); filteringImage(); repaint(); try{ Thread.sleep(200); } catch(InterruptedException e) {} } } //定义过虑 private void filteringImage(){ ImageProducer producer = sourceImage.getSource(); producer = new FilteredImageSource(producer,imageFilter); filteredImage = this.createImage(producer); tracker.addImage(filteredImage,1); } void this_mouseClicked(MouseEvent e) { JFileChooser imageChooser = new JFileChooser(); int returnVal = imageChooser.showOpenDialog(this); if(returnVal == JFileChooser.APPROVE_OPTION){ try { m_imageURL = imageChooser.getSelectedFile().toURL(); m_imageName = imageChooser.getSelectedFile().getName(); } catch (MalformedURLException ex) {} } }}class AppletDemo_this_mouseAdapter extends java.awt.event.MouseAdapter { AppletDemo adaptee; AppletDemo_this_mouseAdapter(AppletDemo adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.this_mouseClicked(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -