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

📄 barrier.java

📁 Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套 代码
💻 JAVA
字号:
/*	Pylon objects display an image like a plastic highway barrier/cone.    Author:  David Riley -- Jan, 2005 */    /**	class invariant *   	getWidth() >= 36  AND  getHeight() >= 36   */import java.awt.Toolkit.*;import java.awt.*;import javax.imageio.ImageIO;import java.io.*;import javax.swing.JComponent;public class Barrier extends JComponent implements java.awt.image.ImageObserver {	private java.awt.Image content;	/**	pre:    a proper JPEG image file must be in file /graphics/Pylon.jpg in the     *          same folder as the current .class file     *  post:   an pylon image is instantiated     *          and  getX() == 0   and  getY() == 0        *          and  getWidth() == 36  AND  getHeight() == 36        */	public Barrier()  {		super();		setBounds(0, 0, 36, 36);        setImage("graphics/Barrier.jpg");	} 	/**	post:   Upon repaint the image displayed will be given by the      *          file with complete pathname specified as s      *          (Note that the file should be a gif or jpeg encoding.)       */	private void setImage(String s)  {        java.net.URL url = getClass().getResource(s);  // for applets        if (url == null)   {            url = getClass().getResource("/"+s);            if (url == null)                try {  // for applications                    content = ImageIO.read(new File(s));                    System.out.println("hereh");                } catch(IOException ioe) {                    ioe.printStackTrace();                }            else                content = getToolkit().getImage(url);        } else            content = getToolkit().getImage(url);	}	public void paint(Graphics g)  {		g.drawImage(content, 0, 0, getWidth(), getHeight(), this);	} }

⌨️ 快捷键说明

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