e)方法。
鼠标进入区域就产档枯生事件反应。
如果之前申明了点击事件可以在entered时间里呼行模洞码老叫clicked事件。
<button id="" name="" onclick="岩核js方法辩拆">点这里</button>然后在页面上写Js方法就可以携枣枣了
---------------------------------
哦,不好意思,我看成了html页面的按钮了。
给你一个例子,太难讲了我自己写的
package guidemo
import java.awt.*
import java.awt.event.MouseEvent
import java.awt.event.MouseListener
/**
* <p>Title: 图形用户界面</p>
*
* <p>Description: 简单的图形界面编程</p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author vic
* @version 1.0
*/
public class ColorFrame extends Frame implements MouseListener {
Label L//标签
TextField T//文本域
Button B1, B2//按钮
public ColorFrame() {
this.setLayout(null)//想要手动指定各组件的的位置
L = new Label("输入学号:")//设定标签L内容
L.setBounds(60, 50, 50, 25)//设定标签L外观
this.add(L)//将标空辩签L添加到窗口中
T = new TextField("请在这里输入")//设定文本域T的内容
T.setBounds(125, 50, 90, 25)//设定文本域T的外观
this.add(T)//将文本域T添加到窗口中
B1 = new Button("变红!")//设定按钮B1的敏枯内容
B1.setBounds(25, 90, 90, 25)//设定按钮B1的外观
B1.addMouseListener(this)//在B1上注册鼠标监听器
this.add(B1)//将按钮B1添加到窗口中
B2 = new Button("变绿!")
B2.setBounds(125, 90, 90, 25)
B2.addMouseListener(this)
this.add(B2)
WindowDestroyer Listener = new WindowDestroyer()//创建关闭窗口监听器
this.addWindowListener(Listener)//将监听器添加到窗口中
this.setBackground(Color.yellow)//设定窗口背景颜色
this.setTitle("This is Frame!")//设定窗口标题文字
this.setBounds(0, 0, 250, 220)//设定窗口位置和大小
this.setVisible(true)//显示窗口
}
public void mouseClicked(MouseEvent e) {
if (e.getComponent() == B1) {//getComponent返回按钮上面斗拿缺的字符串
this.setBackground(Color.red)
}
if (e.getComponent() == B2) {
this.setBackground(Color.green)
}
}
public void mouseExited(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public static void main(String[] args) {
new ColorFrame()
}
}
希望能解决您的问题。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)