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

  53.         }
複製代碼

TOP

返回列表