java程序设计基础教程第二版: p212_14

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Cursor.*;
public class naixin extends Frame{
    Choice choice_cursor=new Choice();
    Label l = new Label("打击防恐惧的肌肤的 ");
    public void  init(){
    setLayout(new FlowLayout());
    choice_cursor.add("DEFAULT_CURSOR");
    choice_cursor.add("CROSSHAIR_CURSOR");
    choice_cursor.add("TEXT_CURSOR");
    choice_cursor.add("WAIT_CURSOR");
    choice_cursor.add("SW_RESIZE_CURSOR");
    choice_cursor.add("SE_RESIZE_CURSOR");
    choice_cursor.add("NW_RESIZE_CURSOR");
    choice_cursor.add("NE_RESIZE_CURSOR");
    choice_cursor.add("N_RESIZE_CURSOR");
    choice_cursor.add("S_RESIZE_CURSOR");
    choice_cursor.add("W_RESIZE_CURSOR");
    choice_cursor.add("E_RESIZE_CURSOR");
    choice_cursor.add("HAND_CURSOR");
    choice_cursor.add("MOVE_CURSOR");//常量表值:13
    choice_cursor.add("CUSTOM_CURSOR");//常量表值:-1
    choice_cursor.addItemListener(new ItemListener(){
        public void itemStateChanged(ItemEvent e){
           
            try{
               
                //Sring str_select=choice_cursor.getSelectedItem();
                int select = choice_cursor.getSelectedIndex();
                l.setText("select="+select);
             
              if(select==14){
                  select=-1;       
                  l.setText("select="+select);         
                  setCursor(new Cursor(select));
                  }
              else{
                  setCursor(new Cursor(select));//值取不到-1,另外处理
                  }
             
             
            }
            catch(Exception e2){
                e2.printStackTrace();
            }
        }
    });
   
          add(choice_cursor);
          add(l);
  }

/*
  public void paint(Graphics g){
      g.setColor(Color.red);
      g.drawString("Exception...",0,0);
      }
  public void  start(){
         
      }
  public  void stop(){}
  */
  public static void main(String[]args){
      naixin f=new naixin();
      f.setSize(400,400);
      f.setVisible(true);
      f.validate();
        f.init();     
        f.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e){
                System.exit(0);}
            });
      }
 

}

/*
cursor 常量表:
 public static final int CROSSHAIR_CURSOR 1
 public static final int CUSTOM_CURSOR -1
 public static final int DEFAULT_CURSOR 0
 public static final int E_RESIZE_CURSOR 11
 public static final int HAND_CURSOR 12
 public static final int MOVE_CURSOR 13
 public static final int N_RESIZE_CURSOR 8
 public static final int NE_RESIZE_CURSOR 7
 public static final int NW_RESIZE_CURSOR 6
 public static final int S_RESIZE_CURSOR 9
 public static final int SE_RESIZE_CURSOR 5
 public static final int SW_RESIZE_CURSOR 4
 public static final int TEXT_CURSOR 2
 public static final int W_RESIZE_CURSOR 10
 public static final int WAIT_CURSOR 3

           
 */  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值