欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

學(xué)習(xí)筆記二十六:事件處理(二) - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網(wǎng)站建設(shè)-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設(shè)/小程序開發(fā)/軟件開發(fā)

知識(shí)

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們?cè)谧非笃湟曈X表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營(yíng)銷的便利,運(yùn)營(yíng)的高效,讓網(wǎng)站成為營(yíng)銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!

您當(dāng)前位置>首頁(yè) » 新聞資訊 » 技術(shù)分享 >

學(xué)習(xí)筆記二十六:事件處理(二)

發(fā)表時(shí)間:2020-11-13

發(fā)布人:葵宇科技

瀏覽次數(shù):60


在這個(gè)并非盡善盡美的世界上,勤奮會(huì)得到報(bào)償,而游手好閑則要受到懲罰。——毛姆


本講內(nèi)容:MouseEvent 、MouseMotionListener


一、MouseEvent   讓鼠標(biāo)能知道鼠標(biāo)按下的消息、知道點(diǎn)擊的位置等五個(gè)方法。
MouseMotionListener鼠標(biāo)拖動(dòng)坐標(biāo)、鼠標(biāo)移動(dòng)坐標(biāo)二個(gè)方法。



public class Text extends JFrame {
	MyPanel mb=null;
	
	public static void main(String[] args) {
		Text t=new Text();//每定義一個(gè) t 都會(huì)產(chǎn)生一個(gè)對(duì)應(yīng)的this
	}
	
	public Text() {
		mb=new MyPanel();
		this.addMouseListener(mb);//添加監(jiān)聽   
		this.addMouseMotionListener(mb);
		this.add(mb);
		
		//設(shè)置窗體屬性
		this.setTitle("技術(shù)大牛—小勁");
		this.setLocation(300, 300);
		this.setSize(400,400);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}

class MyPanel extends JPanel implements MouseListener,MouseMotionListener{
	public void paint(Graphics g) {
		super.paint(g);
	}

	//MouseListener  接口方法
	//鼠標(biāo)被點(diǎn)擊(鼠標(biāo)按下然后松開后執(zhí)行)
	public void mouseClicked(MouseEvent e) {
		System.out.println("鼠標(biāo)點(diǎn)擊了 x="+e.getX()+"y="+e.getY());
	}

	//鼠標(biāo)移動(dòng)到MyPanel
	public void mouseEntered(MouseEvent e) {
		System.out.println("鼠標(biāo)移動(dòng)到MyPanel");
	}

	//鼠標(biāo)離開MyPanel
	public void mouseExited(MouseEvent e) {
		System.out.println("鼠標(biāo)離開MyPanel");
	}

	//鼠標(biāo)按下
	public void mousePressed(MouseEvent e) {
		System.out.println("鼠標(biāo)按下");
	}

	//鼠標(biāo)松開
	public void mouseReleased(MouseEvent e) {
		System.out.println("鼠標(biāo)松開");
	}

	
	//MouseMotionListener  接口方法
	//鼠標(biāo)拖動(dòng)
	public void mouseDragged(MouseEvent e) {
		System.out.println("鼠標(biāo)拖拽的當(dāng)前坐標(biāo)  x="+e.getX()+"y="+e.getY());
	}

	//鼠標(biāo)移動(dòng)
	public void mouseMoved(MouseEvent e) {
		System.out.println("鼠標(biāo)當(dāng)前坐標(biāo)  x="+e.getX()+"y="+e.getY());		
	}
}

二、KeyListener 鍵盤事件有三個(gè)方法。WindowListener 窗口事件有七個(gè)方法。
public class Text extends JFrame {
	MyPanel mb=null;
	
	public static void main(String[] args) {
		Text t=new Text();
	}
	
	public Text() {
		mb=new MyPanel();
		this.addKeyListener(mb);
		this.addWindowListener(mb);
		this.add(mb);
		
		//設(shè)置窗體屬性
		this.setTitle("技術(shù)大?!?quot;);
		this.setLocation(300, 300);
		this.setSize(400,400);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}

class MyPanel extends JPanel implements KeyListener,WindowListener{
	public void paint(Graphics g) {
		super.paint(g);
	}

	//鍵被按下  
	public void keyPressed(KeyEvent e) {
		System.out.println(e.getKeyChar()+"鍵被按下了");//e.getKeyCode()是ASCII碼
	}

	//鍵被釋放  
	public void keyReleased(KeyEvent e) {
		
	}

	//鍵的一個(gè)值被打印輸出(上下左右鍵等不會(huì)執(zhí)行,因?yàn)闆]打印出)
	public void keyTyped(KeyEvent e) {
		
	}

	
	//窗口激活了(窗口還原后即激活)
	public void windowActivated(WindowEvent e) {
		System.out.println("窗口激活了");
	}

	//窗口關(guān)閉
	public void windowClosed(WindowEvent e) {//很少用到
		System.out.println("窗口關(guān)閉");
	}

	//窗口正在關(guān)閉
	public void windowClosing(WindowEvent e) {
		System.out.println("窗口正在關(guān)閉");
	}

	//窗口失去激活(窗口最小化)
	public void windowDeactivated(WindowEvent e) {
		System.out.println("窗口失去激活");
	}

	//窗口還原
	public void windowDeiconified(WindowEvent e) {
		System.out.println("窗口還原");
	}

	//窗口最小化
	public void windowIconified(WindowEvent e) {
		System.out.println("窗口最小化");
	}

	 //窗口打開
	public void windowOpened(WindowEvent e) {
		System.out.println("窗口打開");	
	}
}



本講就到這里,Take your time and enjoy it

相關(guān)案例查看更多