⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example7_30.java

📁 不错的教程 适合中高级人员的使用
💻 JAVA
字号:
import java.awt.*;import java.awt.event.*;import javax.swing.SwingUtilities;
class Win extends Frame implements MouseListener,MouseMotionListener
{  Button button;TextField text; 
   int x,y;        //记录鼠标位置用的变量。
   boolean move=false;
   Win()
   {  button=new Button("用鼠标拖动我");
      text=new TextField("用鼠标拖动我",8);
	  button.addMouseListener(this);
	  button.addMouseMotionListener(this);
	  text.addMouseListener(this);
	  text.addMouseMotionListener(this);
	  addMouseMotionListener(this);
	  setLayout(new FlowLayout());
	  add(button);
	  add(text);
	  addWindowListener(new WindowAdapter()
	      {public void windowClosing(WindowEvent e)
			  {System.exit(0);}
	       }
	  );
	  setBounds(10,10,350,300);
      setVisible(true);
	  validate();
    }   
   public void mousePressed(MouseEvent e){}
   public void mouseEntered(MouseEvent e){}
   
   public void mouseReleased(MouseEvent e)
   {  move=false;   } 
   public void mouseExited(MouseEvent e){}
   public void mouseClicked(MouseEvent e){}
   public void mouseMoved(MouseEvent e){}
   public void mouseDragged(MouseEvent e)
   {
	   Component com=null;
	   if(e.getSource() instanceof Component)
	   {
		   com=(Component) e.getSource();
		   if(com!=this)
			   move=true;
		   e=SwingUtilities.convertMouseEvent(com,e,this);
		   if(move)
		   {
			   x=e.getX();
			   y=e.getY();
			   int w=com.getSize().width,h=com.getSize().height;
			   com.setLocation(x-w/2,y-h/2);
		   }
	   }
   }
}
 
public class Example7_30
{  public static void main(String args[])
   {  new Win();
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -