返回列表 發帖
  1. package ch87;
  2. import javax.swing.*;
  3. public class ch87 {

  4.         public static void main(String[] args) {
  5.                 private JFrame fm;
  6.                 private JLabel lb;
  7.                 private ImageIcon icon,target;
  8.                 private int x=100, y=100;
  9.                
  10.                
  11.                 ch87()
  12.                 {
  13.                         icon=new ImageIcon(Ch87.class.getResource("pic/star.png"));
  14.                         target=new ImageIcon(Ch87.class.getResource("pic/star.png"));
  15.                         
  16.                         lb=new JLabel(target);
  17.                         lb.setBounds(x, y, 128, 128);
  18.                         
  19.                         fm=new JFrame("滑鼠指標牽引圖形");
  20.                         fm.setBounds(100, 100, 420, 320);
  21.                         fm.setIconImage(icon.getImage());
  22.                         fm.setVisible(true);
  23.                         fm.setResizable(false);
  24.                         fm.setLayout(null);
  25.                         fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  26.                         fm.add(lb);
  27.                         fm.addMouseListener(this);
  28.                 }
  29.                 public void mousePressed(MouseEvent e);
  30.                 {
  31.                     if(e.getClickCount)()==1)
  32.                     {
  33.                          x=e.getX()-3;
  34.                          y=e.getY()-25;                 
  35.                     }
  36.                     if(e.getClickCount)()==1)
  37.                     {
  38.                          x=e.getX()-3-64;
  39.                          y=e.getY()-25-64;                 
  40.                     }
  41.                     lb.setLocation(x, y);
  42.                 }
  43.                 public void mouseRleased(mouseEvent e){}
  44.                
  45.                 public void mouseClicked(mouseEvent e){}
  46.                
  47.                 public void mouseEntered(mouseEvent e){}
  48.                
  49.                 public void mouseExcited(mouseEvent e){}
  50.                
  51.                 public static void main(String[] args){
  52.                         ch87 app=new ch87();
  53.             }

  54.         }
複製代碼

TOP

返回列表