好久没发表文章了!
最近在研究Applet怎么处理图片缩放,现简单做了一个例子,与大家分享!
package applet;
import Java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.Swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
public class ImageApplet extends JApplet {
private JPanel jContentPane = null;
private JPanel jPanel = null;
ImageIcon imageIcon = new ImageIcon("images/icon/common/det_dis.gif");
/**
* This is the default constructor
*/
public ImageApplet() {
super();
}
/**
* This method initializes this
*
* @return void
*/
public void init() {
this.setSize(640, 480);
this.setContentPane(getJContentPane());
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(new MainPanel(imageIcon), null);
}
return jContentPane;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
class MainPanel extends JPanel implements MouseListener,
MouseMotionListener {
int x1, y1;
//用来表示向东、南、西、北、东、南、东、北、西南、西北八个方向缩放点
private JLabel northWest = null;
private JLabel north = null;
private JLabel northEast = null;
private JLabel east = null;
private JLabel southEast = null;
private JLabel south = null;
private JLabel southWest = null;
private JLabel west = null;
//图片
ImageIcon imageIcon = null;
//是否可缩放标记
boolean isSelected = false;
public MainPanel(ImageIcon imageIcon) {
this.imageIcon = imageIcon;
this.setBounds(256,107,40,30);
x1 = this.getWidth();
y1 = this.getHeight();
//初始化东、南、西、北、东、南、东、北、西南、西北八个方向缩放点
northWest = new JLabel();
northWest.setText("");
northWest.setBorder(new LineBorder(Color.WHITE, 1));
northWest.addMouseListener(this);
northWest.addMouseMotionListener(this);
northWest.setVisible(false);
north = new JLabel();
north.setText("");
north.setBorder(new LineBorder(Color.WHITE, 1));
north.addMouseListener(this);
north.addMouseMotionListener(this);
north.setVisible(false);
northEast = new JLabel();
northEast.setText("");
northEast.setBorder(new LineBorder(Color.WHITE, 1));
northEast.addMouseListener(this);
northEast.addMouseMotionListener(this);
northEast.setVisible(false);
east = new JLabel();
east.setText("");
east.setBorder(new LineBorder(Color.WHITE, 1));
east.addMouseListener(this);
east.addMouseMotionListener(this);
east.setVisible(false);
southEast = new JLabel();
southEast.setText("");
southEast.setBorder(new LineBorder(Color.WHITE, 1));
southEast.addMouseListener(this);
southEast.addMouseMotionListener(this);
southEast.setVisible(false);
south = new JLabel();
south.setText("");
south.setBorder(new LineBorder(Color.WHITE, 1));
south.addMouseListener(this);
south.addMouseMotionListener(this);
south.setVisible(false);
southWest = new JLabel();
southWest.setText("");
southWest.setBorder(new LineBorder(Color.WHITE, 1));
southWest.addMouseListener(this);
southWest.addMouseMotionListener(this);
southWest.setVisible(false);
west = new JLabel();
west.setText("");
west.setBorder(new LineBorder(Color.WHITE, 1));
west.addMouseListener(this);
west.addMouseMotionListener(this);
west.setVisible(false);
//东、南、西、北、东、南、东、北、西南、西北八个方向缩放点的坐标
northWest.setBounds(0, 0, 5, 5);
north.setBounds((x1 - 3) / 2, 0, 5, 5);
northEast.setBounds(x1 - 5, 0, 5, 5);
east.setBounds(x1 - 5, (y1 - 3) / 2, 5, 5);
southEast.setBounds(x1 - 5, y1 - 5, 5, 5);
south.setBounds((x1 - 3) / 2, y1 - 5, 5, 5);
southWest.setBounds(0, y1 - 5, 5, 5);
west.setBounds(0, (y1 - 3) / 2, 5, 5);
this.setLayout(null);
this.setMinimumSize(new Dimension(20, 20));
this.addMouseListener(this);
this.addMouseMotionListener(this);
//加入缩放点到jpanel中
this.add(northWest, null);
this.add(north, null);
this.add(northEast, null);
this.add(east, null);
this.add(southEast, null);
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!



