package think_in_java;
import java.awt.*;
import javax.swing.*;
import java.net.*;/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2003-7-25
* Time: 22:23:25
* To change this template use Options | File Templates.
*/
public class DisplayImage extends JApplet {
public void init(){
ImageIcon icon = null;
try{
icon = new ImageIcon(new URL(getCodeBase(),"Images/wrox_logo.gif"));
}
catch(MalformedURLException e){
System.out.println("Failed to create URL:\n" + e);
return;
}
int imageWidth = icon.getIconWidth(); // get icon width
int imageHeight = icon.getIconHeight(); // get icon its height
resize(imageWidth,imageHeight); // set applet size to fit the image
//create panel a showing the image
ImagePanel imagePanel = new ImagePanel(icon.getImage) ;//没完,明天补~~~
import java.awt.*;
import javax.swing.*;
import java.net.*;/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2003-7-25
* Time: 22:23:25
* To change this template use Options | File Templates.
*/
public class DisplayImage extends JApplet {
public void init(){
ImageIcon icon = null;
try{
icon = new ImageIcon(new URL(getCodeBase(),"Images/wrox_logo.gif"));
}
catch(MalformedURLException e){
System.out.println("Failed to create URL:\n" + e);
return;
}
int imageWidth = icon.getIconWidth(); // get icon width
int imageHeight = icon.getIconHeight(); // get icon its height
resize(imageWidth,imageHeight); // set applet size to fit the image
//create panel a showing the image
ImagePanel imagePanel = new ImagePanel(icon.getImage) ;//没完,明天补~~~
import java.awt.*;
import javax.swing.*;
import java.net.*;/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2003-7-25
* Time: 22:23:25
* To change this template use Options | File Templates.
*/
public class DisplayImage extends JApplet {
public void init(){
ImageIcon icon = null;
try{
icon = new ImageIcon(new URL(getCodeBase(),"Images/wrox_logo.gif"));
}
catch(MalformedURLException e){
System.out.println("Failed to create URL:\n" + e);
return;
}
int imageWidth = icon.getIconWidth(); // get icon width
int imageHeight = icon.getIconHeight();// get icon its height
resize(imageWidth,imageHeight); // set applet size to fit the image
//create panel a showing the image
ImagePanel imagePanel = new ImagePanel(icon.getImage());
getContentPane().add(imagePanel);
//add the panel to the content pane
}
//class representing a panel displaying an image
class ImagePanel extends JPanel
{
public ImagePanel(Image image)
{
this.image = image;
}
public void paint(Graphics g)
{
g.drawImage(image,0,0,this); //display the image
}
Image image; // the image
}}