日期:2014-05-17 浏览次数:21147 次
import java.applet.Applet;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import javax.swing.JButton;
public class AppletDemo extends Applet {
public void init() {
int width = 300;
int height = 200;
final BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics g2 = image.getGraphics();
g2.setColor(Color.WHITE);
g2.fillRect(0, 0, width, height);
JButton save = new JButton("save");
JButton link = new JButton("link");
pointX = new ArrayList();
pointY = new ArrayList();
save.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
try {
ImageIO .write(image, "jpg", new File("c:/test.jpg"));
} catch (IOException e