在使用applet的java程序中,当鼠标移动时,marquee如何停止? [英] In java program using applet how marquee stops when mouse move on it ?

查看:57
本文介绍了在使用applet的java程序中,当鼠标移动时,marquee如何停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的计划。我为Marquee制作程序,但我还要添加什么.......



This is my program. I make program for Marquee but What else I have to add.......

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Twoo extends Frame implements Runnable
{
	private int x;
	private int y;
	Thread t1;
	public Twoo(String title)
	{
		super(title);
		t1 = new Thread(this,"thread1");
		t1.start();
		x=590;
		y=0;
	}
	public void run()
	{
		while (true)
		{
			try
			{ 	x--;	
				y++;
				Thread.sleep(10);
				repaint();
				if(x==0 && y==590){
					
					for(int i=0 ; i< 590;i++){
						x++;
						y--;
						Thread.sleep(10);
						repaint();
						
					}

				}
				

			}
			catch (InterruptedException ie)
			{
				ie.printStackTrace();
			}
			
		}
	}
	public void paint(Graphics g)
	{
		g.setColor(Color.blue);
		g.setFont(new Font("Arial",Font.BOLD|Font.ITALIC,20));
		g.drawString("Mumbai, Rohan Maharashtra",x,300);
		g.drawString("Mumbai, Maharashtra",y,300);
		g.drawString("Mumbai, Maharashtra",200,x);
		g.drawString("Mumbai, Maharashtra",200,y);

	}
	public static void main(String[] args) 
	{
		Frame f=new TwoString("My Thread Frame");
		f.setSize(800,500);
		f.setVisible(true); 
	}
		
}





我尝试过:



我试图通过选框使文本从左向右滚动,但我想在鼠标移动时停止它。



What I have tried:

I tried to make a text to scroll from left to right by marquee, but I want to stop it when mouse move on it.

推荐答案

您需要添加MouseListener,请参阅 jframe mouselistener - Google搜索 [ ^ ]。
You need to add a MouseListener, see jframe mouselistener - Google Search[^].

这篇关于在使用applet的java程序中,当鼠标移动时,marquee如何停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆