第6周作业-图像缩放显示(改)

来源:互联网 发布:中文域名有必要注册吗 编辑:程序博客网 时间:2024/05/29 19:34
package 作业;   import java.awt.*;  import javax.swing.*;    public class ShowImgApp {          public static void main(String[] args) {                  ImageFrame frame = new ImageFrame();          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);          frame.setVisible(true);      }  }    class ImageFrame extends JFrame{      public ImageFrame(){          setTitle("图像缩放");          setSize(WIDTH,HEIGHT);          ImagePanel panel = new ImagePanel();          Container contentPane = getContentPane();          contentPane.add(panel);      }      public static final int WIDTH = 488;      public static final int HEIGHT = 375;     }    class ImagePanel extends JPanel{      public ImagePanel(){          //Image img1;          img1 = Toolkit.getDefaultToolkit().getImage("白云山.jpg");          MediaTracker tracker = new MediaTracker(this);          tracker.addImage(img1, 1);          try{              tracker.waitForID(1);          }          catch(InterruptedException excetion){}      }      public void paintComponent(Graphics g){          //super.paintComponent(g);          int img1Width = img1.getWidth(this);          int img1Height = img1.getHeight(this);          g.drawImage(img1, 5, 10, this);          g.drawImage(img1, 150, 40, WIDTH/2, HEIGHT/2, this);          g.drawImage(img1, 5, 100, WIDTH*2, HEIGHT*2, this);                          }      private Image img1;  }  

0 0
原创粉丝点击