⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsframeborderblock.java

📁 Java自定义窗体JsFrame。简介见:http://jason0086.spaces.live.com/Blog/cns!A797D0C5C0C13C92!518.entry
💻 JAVA
字号:
package com.hfkj.jsframe.border;

import java.awt.Cursor;
import java.awt.Frame;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import com.hfkj.jsframe.component.JsComponent;

/**
 * The <code>JsFrameBorderBlock</code> class is for one of the eight border blocks
 * indicated by the following constraints in the <code>JsFrame</code>:
 * <p>
 * <ul>
 * <li><code>NORTHWEST</code>:
 * The northwest portion of the layout of the <code>JsFrame</code>.
 * <li><code>NORTH</code>:
 * the north portion of the layout of the <code>JsFrame</code>.
 * <li><code>NORTHEAST</code>:
 * The northeast portion of the layout of the <code>JsFrame</code>.
 * <li><code>WEST</code>:
 * The west portion of the layout of the <code>JsFrame</code>.
 * <li><code>EAST</code>:
 * The east portion of the layout of the <code>JsFrame</code>.
 * <li><code>SOUTHWEST</code>:
 * The southwest portion of the layout of the <code>JsFrame</code>.
 * <li><code>SOUTH</code>:
 * The south portion of the layout of the <code>JsFrame</code>.
 * <li><code>SOUTHEAST</code>:
 * The southeast portion of the layout of the <code>JsFrame</code>.
 * </ul>
 * 
 * @see JsFrameBorderBlockUI
 * @see com.hfkj.jsframe.frame.JsFrame
 * @see JsFrameBorder
 * 
 * @version 1.0 01/05/09
 * @author Jason (MSN:www.jason0086.com@hotmail.com)
 */
public class JsFrameBorderBlock extends JsComponent implements MouseListener, MouseMotionListener {
	
	/**
	 * The northwest constraint.
	 */
	public static final int NORTHWEST = 1;
	
	/**
	 * The north constraint. 
	 */
	public static final int NORTH = 2;
	
	/**
	 * The northeast constraint.
	 */
	public static final int NORTHEAST = 3;
	
	/**
	 * The west constraint.
	 */
	public static final int WEST = 4;
	
	/**
	 * The east constraint.
	 */
	public static final int EAST = 5;
	
	/**
	 * The southwest constraint.
	 */
	public static final int SOUTHWEST = 6;
	
	/**
	 * The south constraint.
	 */
	public static final int SOUTH = 7;
	
	/**
	 * The southeast constraint.
	 */
	public static final int SOUTHEAST = 8;
	
	/**
	 * The root frame.
	 */
	protected Frame rootFrm = null;
	
	/**
	 * The location, which should be one of the following:
	 * <code>NORTHWEST</code>, <code>NORTH</code>, <code>NORTHEAST</code>,
	 * The northeast portion of the layout of the <code>JsFrame</code>.
	 * <code>WEST</code>, <code>EAST</code>, <code>SOUTHWEST</code>,
	 * <code>SOUTH</code>, <code>SOUTHEAST</code>.
	 */
	protected int locationInt = 0;
	
	/**
	 * The mouse point.
	 */
	protected Point mousePnt = null;
	
	private static final long serialVersionUID = -1386168047687544997L;
	
	/**
	 * Constructs a js frame border block with the given location for the given frame.
	 * @param location the location indicator for this <code>JsFrameBorderBlock</code>
	 * @param rootFrame the frame which is the host of this <code>JsFrameBorderBlock</code>
	 */
	public JsFrameBorderBlock(int location, Frame rootFrame) {
		this.locationInt = location;
		this.rootFrm = rootFrame;
	}
	
	@Override
	public void setEnabled(boolean enabled) {
		if (enabled) {
			this.addMouseListener(this);
			this.addMouseMotionListener(this);
		}
		else {
			this.removeMouseListener(this);
			this.removeMouseMotionListener(this);
		}
	}
	
	/**
	 * Implements <code>java.awt.event.MouseMotionListener</code>.
	 */
	public void mouseDragged(MouseEvent e) {
        Point xPnt = MouseInfo.getPointerInfo().getLocation();
        int xDisplacementInt = xPnt.x - mousePnt.x;
        int yDisplacementInt = xPnt.y - mousePnt.y;
        int x = this.rootFrm.getX();
        int y = this.rootFrm.getY();
        int w = this.rootFrm.getWidth();
        int h = this.rootFrm.getHeight();
        if (this.locationInt == NORTHWEST) {
        	x += xDisplacementInt;
        	y += yDisplacementInt;
        	w -= xDisplacementInt;
        	h -= yDisplacementInt;
        }
        else if (this.locationInt == NORTH) {
        	y += yDisplacementInt;
        	h -= yDisplacementInt;
        }
        else if (this.locationInt == NORTHEAST) {
        	y += yDisplacementInt;
        	w += xDisplacementInt;
        	h -= yDisplacementInt;
        }
        else if (this.locationInt == WEST) {
        	x += xDisplacementInt;
        	w -= xDisplacementInt;
        }
        else if (this.locationInt == EAST) {
        	w += xDisplacementInt;
        }
        else if (this.locationInt == SOUTHWEST) {
        	x += xDisplacementInt;
        	w -= xDisplacementInt;
        	h += yDisplacementInt;
        }
        else if (this.locationInt == SOUTH) {
        	h += yDisplacementInt;
        }
        else if (this.locationInt == SOUTHEAST) {
        	w += xDisplacementInt;
        	h += yDisplacementInt;
        }
        this.mousePnt = xPnt;
        this.rootFrm.setLocation(x, y);
        this.rootFrm.setSize(w, h);
        this.rootFrm.setVisible(true);
	}

	/**
	 * Implements <code>java.awt.event.MouseMotionListener</code>.
	 */
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	/**
	 * Implements <code>java.awt.event.MouseListener</code>.
	 */
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	/**
	 * Implements <code>java.awt.event.MouseListener</code>.
	 */
	public void mouseEntered(MouseEvent e) {
		if (this.locationInt == NORTHWEST) {
			this.setCursor(new Cursor(Cursor.NW_RESIZE_CURSOR));
		}
		else if (this.locationInt == NORTH) {
			this.setCursor(new Cursor(Cursor.N_RESIZE_CURSOR));
		}
		else if (this.locationInt == NORTHEAST) {
			this.setCursor(new Cursor(Cursor.NE_RESIZE_CURSOR));
		}
		else if (this.locationInt == WEST) {
			this.setCursor(new Cursor(Cursor.W_RESIZE_CURSOR));
		}
		else if (this.locationInt == EAST) {
			this.setCursor(new Cursor(Cursor.E_RESIZE_CURSOR));
		}
		else if (this.locationInt == SOUTHWEST) {
			this.setCursor(new Cursor(Cursor.SW_RESIZE_CURSOR));
		}
		else if (this.locationInt == SOUTH) {
			this.setCursor(new Cursor(Cursor.S_RESIZE_CURSOR));
		}
		else if (this.locationInt == SOUTHEAST) {
			this.setCursor(new Cursor(Cursor.SE_RESIZE_CURSOR));
		}
		else {
			throw new IllegalArgumentException("Invalid direction.");
		}
	}

	/**
	 * Implements <code>java.awt.event.MouseListener</code>.
	 */
	public void mouseExited(MouseEvent e) {
		this.setCursor((new Cursor(Cursor.DEFAULT_CURSOR)));
	}

	/**
	 * Implements <code>java.awt.event.MouseListener</code>.
	 */
	public void mousePressed(MouseEvent e) {
		this.mousePnt = MouseInfo.getPointerInfo().getLocation();
	}

	/**
	 * Implements <code>java.awt.event.MouseListener</code>.
	 */
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -