📄 jframeex.java
字号:
///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2000 Davanum Srinivas (dims@geocities.com)
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
///////////////////////////////////////////////////////////////////////////////
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
// This is an undocumented package.
import sun.awt.*;
public class JFrameEx extends JFrame
{
static {
//Load the library that contains the subclassing code.
System.loadLibrary("MouseWheel");
}
// native entry point for subclassing the JFrame window
public native void setHook(int hwnd);
// native entry point for removing the hook.
public native void resetHook(int hwnd);
// this is the function which serves as a call back when
// a mouse wheel movement is detected.
public void notifyMouseWheel(short fwKeys,short zDelta,long xPos, long yPos)
{
// Convert screen coordinates to component specific offsets.
Point p = new Point((int)xPos,(int)yPos);
SwingUtilities.convertPointFromScreen(p,this);
// Find the embedded Swing component which should receive the scroll messages
Component c = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
try
{
// Get the scroll pane for the widget.
JScrollPane scrollPane = (JScrollPane) c.getParent().getParent();
// Get the vertical scrollbar for the scroll pane.
JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
// Get the current value and set the new value depending on
// the direction of the mouse wheel.
int nValue = scrollBar.getValue();
nValue = nValue + ((zDelta > 0) ? 5 : -5);
scrollBar.setValue(nValue);
} catch (Exception e){
// Ignore exceptions.
}
}
// constructor which specifies the Title
public JFrameEx(String strTitle)
{
super(strTitle);
}
// Returns the HWND for canvas.
// This is undocumented, but works on JDK1.1.8, JDK1.2.2 and JDK1.3
public int getHWND()
{
DrawingSurfaceInfo drawingSurfaceInfo;
Win32DrawingSurface win32DrawingSurface;
int hwnd = 0;
// Get the drawing surface
drawingSurfaceInfo =
((DrawingSurface)(getPeer())).getDrawingSurfaceInfo();
if (null != drawingSurfaceInfo) {
drawingSurfaceInfo.lock();
// Get the Win32 specific information
win32DrawingSurface =
(Win32DrawingSurface)drawingSurfaceInfo.getSurface();
hwnd = win32DrawingSurface.getHWnd();
drawingSurfaceInfo.unlock();
}
return hwnd;
}
// subclass the window once it has been created.
public void addNotify()
{
super.addNotify();
setHook(getHWND());
}
// remove the subclass-ing when the window is about to be destroyed.
public void removeNotify()
{
resetHook(getHWND());
super.removeNotify();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -