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

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

  52.         }
複製代碼

TOP

返回列表