super.paintComponent(g);
// t = new AffineTransform();
// if(image==null) return;
//g.drawImage(image,0,0,300,200,null) ;
if (image == null)return;
g.drawImage(image, x, y, width, length, null);
}
}
class myJPanel extends JLabel {
public Image image2;
public int x;
public int y;
public int width;
public int length;
public Rectangle up1;
public Rectangle up2;
public Rectangle up3;
public Rectangle middle1;
public Rectangle middle2;
public Rectangle down1;
public Rectangle down2;
public Rectangle down3;
public Rectangle itself;
public myJPanel() {
try {
image2 = ImageIO.read(new File("32.png"));
length = image2.getHeight(this);
width = image2.getWidth(this);
x = this.getX();
y = this.getY();
this.setPreferredSize(new Dimension(width, length));
} catch (IOException exception) {
}
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (image2 == null)return;
g.drawImage(image2, x, y, width, length, null);
up1 = new Rectangle(x, y, 8, 8);
up2 = new Rectangle(x + width / 2, y, 8, 8);
up3 = new Rectangle(x + width - 8, y, 8, 8);
middle1 = new Rectangle(x, y + length / 2, 8, 8);
middle2 = new Rectangle(x + width - 8, y + length / 2, 8, 8);
down1 = new Rectangle(x, y + length - 8, 8, 8);
down2 = new Rectangle(x + width / 2, y + length - 8, 8, 8);
down3 = new Rectangle(x + width - 8, y + length - 8, 8, 8);
itself = new Rectangle(x, y, width, length);
g.fillRect(x, y, 8, 8);
g.fillRect(x + width / 2, y, 8, 8);
g.fillRect(x + width - 8, y, 8, 8);
g.fillRect(x, y + length / 2, 8, 8);
g.fillRect(x + width - 8, y + length / 2, 8, 8);
g.fillRect(x, y + length - 8, 8, 8);
g.fillRect(x + width / 2, y + length - 8, 8, 8);
g.fillRect(x + width - 8, y + length - 8, 8, 8);
public void jPanel1_mousePressed(MouseEvent e) {
if (jPanel1.up1.contains(e.getX(), e.getY()) == true)
a = 1;
else if (jPanel1.down3.contains(e.getX(), e.getY()) == true)
a = 9;
else if (jPanel1.up2.contains(e.getX(), e.getY()) == true)
a = 2;
else if (jPanel1.down2.contains(e.getX(), e.getY()) == true)
a = 8;
else if (jPanel1.up3.contains(e.getX(), e.getY()) == true)
a = 3;
else if (jPanel1.down1.contains(e.getX(), e.getY()) == true)
a = 7;
else if (jPanel1.middle1.contains(e.getX(), e.getY()) == true)
a = 4;
else if (jPanel1.middle2.contains(e.getX(), e.getY()) == true)
a = 6;
else if (jPanel1.itself.contains(e.getX(), e.getY()) == true) {
a = 10;
xx = e.getX() - jPanel1.x;
yy = e.getY() - jPanel1.y;
} else
a = 0;
}
int xx = 0;
int yy = 0;
BorderLayout borderLayout1 = new BorderLayout();
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenu1 = new JMenu();
JMenuItem jMenuItem1 = new JMenuItem();
JMenuItem jMenuItem2 = new JMenuItem();
public void jPanel1_mouseDragged(MouseEvent e) {
if (a == 1) {
jPanel1.width = jPanel1.width - e.getX() + jPanel1.x;
jPanel1.length = jPanel1.length - e.getY() + jPanel1.y;
jPanel1.x = e.getX();
jPanel1.y = e.getY();
jPanel1.repaint();
} else if (a == 2) {
jPanel1.length = jPanel1.length - e.getY() + jPanel1.y;
jPanel1.y = e.getY();
jPanel1.repaint();
} else if (a == 3) {
jPanel1.length = jPanel1.length - e.getY() + jPanel1.y;
jPanel1.width = e.getX() - jPanel1.x;
jPanel1.y = e.getY();
jPanel1.repaint();
} else if (a == 4) {
jPanel1.width = jPanel1.width - e.getX() + jPanel1.x;
jPanel1.x = e.getX();
jPanel1.repaint();
} else if (a == 6) {
jPanel1.width = e.getX() - jPanel1.x;
//jPanel1.x =e.getX() ;
jPanel1.repaint();
} else if (a == 7) {
jPanel1.width = jPanel1.width - (e.getX() - jPanel1.x);
jPanel1.length = e.getY() - jPanel1.y;
jPanel1.x = e.getX();
jPanel1.y = jPanel1.y;
jPanel1.repaint();
} else if (a == 8) {
jPanel1.length = e.getY() - jPanel1.y;
jPanel1.repaint();
} else if (a == 9) {
public boolean CreateThumbnail() throws Exception
{
//ext是图片的格式 gif JPG 或png
String ext="";
double Ratio=0.0;
File F = new File(fromdir,imgfile);
if (!F.isFile())
throw new Exception(F+" is not image file error in CreateThumbnail!");
//首先判断上传的图片是gif还是JPG ImageIO只能将gif转换为png
if (isJpg(imgfile)){
ext="jpg";
}else{
ext="png";
}
File ThF = new File(todir,sysimgfile+"."+ext);