当前位置: 技术问答>java相关
为什么这个程序画不出东东?
来源: 互联网 发布时间:2015-02-20
本文导语: import java.awt.*; import java.applet.*; public class Class1 extends Applet { Point startpt,endpt; /** * The entry point for the applet. */ public void init() { setBackground(Color.white); } public boolean mousedown (Event evt,int x,int y) ...
import java.awt.*;
import java.applet.*;
public class Class1 extends Applet
{
Point startpt,endpt;
/**
* The entry point for the applet.
*/
public void init()
{
setBackground(Color.white);
}
public boolean mousedown (Event evt,int x,int y)
{
startpt=new Point(x,y);
return true;
}
public boolean mousedrag (Event evt,int x,int y)
{
startpt=new Point(x,y);
repaint();
return true;
}
public boolean mouseup (Event evt,int x,int y)
{
startpt=new Point(x,y);
repaint();
return true;
}
public void paint(Graphics g)
{
if(endpt!=null)
{
g.drawLine(startpt.x,startpt.y,endpt.x,endpt.y);
}
}
}
import java.applet.*;
public class Class1 extends Applet
{
Point startpt,endpt;
/**
* The entry point for the applet.
*/
public void init()
{
setBackground(Color.white);
}
public boolean mousedown (Event evt,int x,int y)
{
startpt=new Point(x,y);
return true;
}
public boolean mousedrag (Event evt,int x,int y)
{
startpt=new Point(x,y);
repaint();
return true;
}
public boolean mouseup (Event evt,int x,int y)
{
startpt=new Point(x,y);
repaint();
return true;
}
public void paint(Graphics g)
{
if(endpt!=null)
{
g.drawLine(startpt.x,startpt.y,endpt.x,endpt.y);
}
}
}
|
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Class1 extends Applet
{
Point startpt,endpt;
boolean t = true;
public void init()
{
setBackground(Color.white);
setForeground(Color.red);
addMouseListener(new MouseListener()
{
public void mouseClicked(MouseEvent e)
{
if (t)
{
startpt=e.getPoint();
t = false;
}
else
{
endpt = e.getPoint();
t = true;
repaint();
}
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
});
}
public void paint(Graphics g)
{
if(endpt!=null)
{
g.drawLine(startpt.x,startpt.y,endpt.x,endpt.y);
System.out.println("Asdf");
}
}
}
import java.applet.*;
import java.awt.event.*;
public class Class1 extends Applet
{
Point startpt,endpt;
boolean t = true;
public void init()
{
setBackground(Color.white);
setForeground(Color.red);
addMouseListener(new MouseListener()
{
public void mouseClicked(MouseEvent e)
{
if (t)
{
startpt=e.getPoint();
t = false;
}
else
{
endpt = e.getPoint();
t = true;
repaint();
}
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
});
}
public void paint(Graphics g)
{
if(endpt!=null)
{
g.drawLine(startpt.x,startpt.y,endpt.x,endpt.y);
System.out.println("Asdf");
}
}
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。