applet如何使用自定义光标?

hugos 2001-12-03 01:08:02
当zoomIn.gif 和 zoomOut.gif是15*15大小时,显示的光标仍然是32*32的,很难看。怎么显示16*16的光标?
如何实现光标透明?
/*
* JAppToolsBar.java
*
* Created on 2001年11月30日, 下午8:04
*/

/**
*
* @author Administrator
*/
import java.awt.*;
import javax.swing.*;

public class JAppToolsBar extends javax.swing.JApplet {

private Cursor cursorZoomIn;
private Image imageZoomIn;
private Cursor cursorZoomOut;
private Image imageZoomOut;
private Cursor cursorDrag;
public int SelectedTools;
public JApplet mapJApplet;
/** Creates new form JAppToolsBar */
public JAppToolsBar() {
initComponents();
RadioGroup1.add(jRadioDrag);
RadioGroup1.add(jRadioZoomIn);
RadioGroup1.add(jRadioZoomOut);
}

public void init(){
imageZoomIn = this.getImage(this.getCodeBase(), "cursor/zoomIn.gif");
cursorZoomIn = this.getToolkit().createCustomCursor(imageZoomIn, new Point(5,5),"ZoomIn");
imageZoomIn = this.getImage(this.getCodeBase(), "cursor/zoomOut.gif");
cursorZoomOut = this.getToolkit().createCustomCursor(imageZoomIn, new Point(5,5),"ZoomOut");
cursorDrag = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
SelectedTools = 1;
}
public void paint(Graphics g){
int x=15, y=15;
Dimension dim = getToolkit().getBestCursorSize(x,y);
g.drawString(Integer.toString(dim.width),10,10);
g.drawString(Integer.toString(dim.height),10,40);
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {//GEN-BEGIN:initComponents
RadioGroup1 = new javax.swing.ButtonGroup();
jRadioDrag = new javax.swing.JRadioButton();
jRadioZoomIn = new javax.swing.JRadioButton();
jRadioZoomOut = new javax.swing.JRadioButton();
jRadioViewAll = new javax.swing.JRadioButton();


getContentPane().setLayout(new java.awt.FlowLayout());

jRadioDrag.setSelected(true);
jRadioDrag.setFont(new java.awt.Font("宋体", 0, 14));
jRadioDrag.setText("\u62d6\u52a8");
jRadioDrag.setBorder(null);
jRadioDrag.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jRadioDragMouseClicked(evt);
}
});

getContentPane().add(jRadioDrag);

jRadioZoomIn.setFont(new java.awt.Font("宋体", 0, 14));
jRadioZoomIn.setText("\u653e\u5927");
jRadioZoomIn.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jRadioZoomInMouseClicked(evt);
}
});

getContentPane().add(jRadioZoomIn);

jRadioZoomOut.setFont(new java.awt.Font("宋体", 0, 14));
jRadioZoomOut.setText("\u7f29\u5c0f");
jRadioZoomOut.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jRadioZoomOutMouseClicked(evt);
}
});

getContentPane().add(jRadioZoomOut);

jRadioViewAll.setFont(new java.awt.Font("宋体", 0, 14));
jRadioViewAll.setText("\u5168\u666f");
getContentPane().add(jRadioViewAll);

}//GEN-END:initComponents

private void jRadioZoomOutMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioZoomOutMouseClicked
mapJApplet = (JApplet)(this.getAppletContext().getApplet("JAppMapArea"));
mapJApplet.setCursor(cursorZoomOut);
SelectedTools = 3;
}//GEN-LAST:event_jRadioZoomOutMouseClicked

private void jRadioZoomInMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioZoomInMouseClicked
mapJApplet = (JApplet)(this.getAppletContext().getApplet("JAppMapArea"));
mapJApplet.setCursor(cursorZoomIn);
SelectedTools = 2;
}//GEN-LAST:event_jRadioZoomInMouseClicked

private void jRadioDragMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioDragMouseClicked
mapJApplet = (JApplet)(this.getAppletContext().getApplet("JAppMapArea"));
mapJApplet.setCursor(cursorDrag);
SelectedTools = 1;
}//GEN-LAST:event_jRadioDragMouseClicked



// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup RadioGroup1;
private javax.swing.JRadioButton jRadioDrag;
private javax.swing.JRadioButton jRadioZoomIn;
private javax.swing.JRadioButton jRadioZoomOut;
private javax.swing.JRadioButton jRadioViewAll;
// End of variables declaration//GEN-END:variables

}
...全文
83 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
hugos 2001-12-06
csdn 的java 版, 人气太差了
  • 打赏
  • 举报
回复
hugos 2001-12-04
没有高手吗?
  • 打赏
  • 举报
回复
skyyoung 2001-12-03
Toolkits implementation uses getBestCursorSize to get the nearest size supported by particular systems, and if you have used an image which has a size different from the value returned by this function, the image will be resized before using it as cursor.

To check if a system supports cursors larger than 32x32, you can get default toolkit, and call getBestCursorSize with the size that you want. If the system supports a larger size, it will return a larger value.

  • 打赏
  • 举报
回复
hugos 2001-12-03
!!!!!
  • 打赏
  • 举报
回复
hugos 2001-12-03
wookooooo, java 高手 在吗?
  • 打赏
  • 举报
回复
发帖
VC/MFC
加入

1.6w+

社区成员

VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
申请成为版主
帖子事件
创建了帖子
2001-12-03 01:08
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……