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

📄 dragwindowcontrol.java

📁 mp3播放功能
💻 JAVA
字号:
package WindowType;

import java.awt.Window;
import java.util.ArrayList;

import WindowType.DragWindowEvent;;
/**
 * Control when Drag the Window 
 * For example,the subWindow will link to the window you drag
 * 
 * @author DuXiaojing
 *@version since 1.0
 */
public class DragWindowControl {
	private Window Window;
	private int X;
	private int Y;
	private ArrayList windowDragListenerList = new ArrayList();

	/**
	 * Constructer to locate the Window object
	 * Create the WindowDrag object to start 
	 * WindowDrag created below
	 * @param Window Control the Window object you drag
	 *
	 */
	public DragWindowControl(Window Window){
		this.Window = Window;
		X = Window.getX();
		Y = Window.getY();
		new WindowDrag().start();
	}
	
/**
 * Get locations of the window dragged to
 *
 * @return the int array 
 */
	private int[] getRealTimeXY(){
		return new int[]{Window.getX(),Window.getY()};
	}
	/**
	 * Answer the windowDragEvent to the Arraylist object 
	 * @param we DragWindowEvent object
	 * @see WindowType.DragWindowEvent
	 */
	private void answerWindowDragEvent(DragWindowEvent we){
		for(int i = 0;i <windowDragListenerList.size();i ++){
			((DragWindowListener)windowDragListenerList.get(i)).windowDragging(we);
		}
	}
	/**
	 * When dragged,add it to the Arraylist object windowDragListenerList
	 * @param wl DragWindowListener 
	 * @see WindowType.DrageWindowListener
	 * 
	 */
	private void addWindowDragListner(DragWindowListener wl){
		windowDragListenerList.add(wl);
	}
	
	/**
	 * Class WindowDrag extends Thread
	 * Override the method run()
	 * @exception InterruptedException Thread sleep with problems
	 */
	private class WindowDrag extends  Thread{

		public void run() {
			// TODO Auto-generated method stub
			while(true){
				int[] newxy = getRealTimeXY();
				if(X != newxy[0] || Y != newxy[1]){
					int deltax = newxy[0] - X;
					int deltay = newxy[1] - Y;
					answerWindowDragEvent(new DragWindowEvent(Window,deltax,deltay));
					X = newxy[0];
					Y = newxy[1];
				}
				
				try {
					sleep(100);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
	}
	
	/**
	 * SubWindowDragListener implenments DragWindowListener
	 * Constructer to send the Window object to the class
	 * Method windowDragging to relocate the position window dragged to
	 * @author DuXiaojing
	 *
	 */
	private class SubWindowDragListener implements DragWindowListener{
		private Window subWindow = null;

		public SubWindowDragListener(Window subWindow) {
			this.subWindow = subWindow;
		}


		public void windowDragging(DragWindowEvent we) {
			// TODO Auto-generated method stub
			if(subWindow.isVisible()){				
				subWindow.setLocation(subWindow.getX()+we.getDelX(), subWindow.getY()+we.getDelY());
			}
		}
		
	}
	/**
	 * Add SubWindow to the prime window
	 * @param subWindow the window sticked to the prime window
	 */
	public void addSubWindow(Window subWindow){
		addWindowDragListner(new SubWindowDragListener(subWindow));
	}
}

⌨️ 快捷键说明

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