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
}