applet截图上传(2)

CutScreen.java
package applet;

import java.awt.AWTException;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Date;

import javax.imageio.ImageIO;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

import netscape.javascript.JSObject;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;

public class CutScreen extends JApplet {
	private static final long serialVersionUID = -267804510087895906L;

	public CutScreen() {
	}

	public void capture() {
		JOptionPane.showMessageDialog(null, "请把要截图的窗口调到最前面!");
		try {
			new ScreenWindow(this);
		} catch (Exception e1) {
			JOptionPane.showConfirmDialog(null, "出现意外错误!", "系统提示",
					JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
		}
	}

 

class ScreenWindow extends JFrame {

		private static final long serialVersionUID = -3758062802950480258L;

		private boolean isDrag = false;

		private int x = 0;

		private int y = 0;

		private int xEnd = 0;

		private int yEnd = 0;

		public ScreenWindow(final CutScreen outer) throws AWTException, InterruptedException {
			Dimension screenDims = Toolkit.getDefaultToolkit().getScreenSize();
			com.sun.awt.AWTUtilities.setWindowOpacity(this, 0.2f);
			this.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent e) {
					if (e.getButton() == MouseEvent.BUTTON3) {
						dispose();
					}
				}

				public void mousePressed(MouseEvent e) {
					x = e.getX();
					y = e.getY();
				}

 

你可能感兴趣的:(JavaScript,java,apache,swing,sun)