为什么在最大化/最小化applet时线条会消失? [英] Why does lines disappear on maximizing/minimizing applet?

查看:88
本文介绍了为什么在最大化/最小化applet时线条会消失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class xy extends Applet implements MouseListener,ActionListener
{	Button b;
	int x1, y1,x2,y2;
	public void init()
	{	b=new Button("Draw Line");	
		add(b);		
		x1=y1=x2=y2=0;
		b.addActionListener(this);
	}
	public void actionPerformed(ActionEvent ae)
{
	if(ae.getSource()==b){
	addMouseListener(this);}
}
	public void mouseClicked(MouseEvent me)
	{
		showStatus( "(" + x1 + "," + y1+ ")" );	
	}
	public void mousePressed(MouseEvent me)
	{
	x1=me.getX();
	y1=me.getY();
	}
	public void mouseReleased(MouseEvent me)
	{
	x2=me.getX();
	y2=me.getY();
	Graphics g = getGraphics();
	me.consume();	
	repaint();
	
	}
	public void mouseExited(MouseEvent me)
	{}
	public void mouseEntered(MouseEvent me)
	{}
	public void paint(Graphics g)
	{
		update(g);
	}
	public void update(Graphics g)
	{
		g.drawLine( x1,y1,x2,y2);
	}

}

推荐答案

当你最小化和最大化你的applet时(在applet查看器中或webbrowser),在清除整个屏幕后进行新的更新调用。因此在更新中,您只绘制最后一行...因此您的所有行都会消失。考虑一些替代机制,例如将所有行存储在堆栈中并在每次调用更新时重新绘制它们。



你也可以使用其他那些awt组件,但请记住覆盖适当的方法。



好​​运
When you minimize and maximize your applet (in applet viewer or webbrowser), a fresh call to update is made after clearing the entire screen. So in update, you only paint the last line... therefore all your lines disappear. Think of some alternate mechanism such as storing all lines in a stack and repainting them everytime update is called.

You can also use swing components other that awt ones, but remember to override the appropriate method.

Good Luck


这篇关于为什么在最大化/最小化applet时线条会消失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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