?? 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 + -