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