
//where initialization occurs:
//Register for mouse events on blankArea and the panel.
blankArea.addMouseListener(this)
addMouseListener(this)
...
public void mousePressed(MouseEvent e) {
saySomething("Mouse pressed # of clicks: "
+ e.getClickCount(), e)
}
public void mouseReleased(MouseEvent e) {
saySomething("Mouse released # of clicks: "
+ e.getClickCount(), e)
}
public void mouseEntered(MouseEvent e) {
saySomething("Mouse entered", e)
}
public void mouseExited(MouseEvent e) {
saySomething("Mouse exited", e)
}
铅纤 public void mouseClicked(MouseEvent e) {
saySomething("Mouse clicked (# of clicks: "
早激帆 + e.getClickCount() + ")", e)
}
void saySomething(String eventDescription, MouseEvent e) {
textArea.append(eventDescription + " detected on "
陆雹 + e.getComponent().getClass().getName()
+ "." + newline)
}
}
一定要用线程,首先,我们先来分析一下如何才能做到让屏幕上的数字不停的变化,这就需要使用线程了,当我槐模行们开始抽奖的按钮的时候,线程启动,此时屏幕铅哗上的数字开始滚动。当我们点击结束按钮的时候,线程终码段止,此时就可以显示出抽奖结果了。import java.util.Scanner/**
*
*/
public class f {
public static void main(String args[]){
Scanner scan = new Scanner(System.in)
System.out.print("请输入抽奖号码上限:")
渣卖蔽 int max = scan.nextInt()
System.out.print("请输入抽奖次数:"配碧)
int n = scan.nextInt()
System.out.print("中奖号码依次为:")
for(int i=0i<ni++){
System.out.print((int)(Math.random()*max+1)+" ")
如州 }
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)