编写一个Applet程序,在Applet中按下鼠标左键时在鼠标位置画圆,按下右键画方,退出时清空。源码如下. 5
运行结果如下:源码:importjava.awt.*;importjava.awt.Event.*;importjava.applet.Applet;publicclas...
运行结果如下:
源码:
import java.awt.*;
import java.awt.Event.*;
import java.applet.Applet;
public class huafangyuan_07 extends Applet implements MouseListener {
int left =-1,right = -1,x=-1,y=-1;/////////////////左右用于记录鼠标左右键,x,y记录鼠标位置
public void init(){
setBackground(Color.BLACK);
addMouseListener(this);
}
public void paint(Graphics g){
if(left == 1){
g.drawOval(x, y, 20, 20);
this.setBackground(Color.green);
}
else if(right == 1){
g.drawRect(x, y, 20, 20);
this.setBackground(Color.red);
}
}
public void mouseClicked(MouseEvent e){
x = e.getX();
y = e.getY();
if(e.getModifiers() == InputEvent.BUTTON1_MASK){
left =1;
right = -1;
repaint();
}
elde if(e.getModifiers() == InputEvent.BUTTON3_MASK){
right = 1;
left = -1;
repaint();
}
}
public void mouseExited(MouseEvent e){
left = -1;right = -1;
repaint();
}
public void mouseReleased(MouseEvent e){
}
public void mouseEntered(MouseEvent e){
}
public void mousepressed(MouseEvent e){
}
}
烦请指正问题出在哪?百般感谢!!! 展开
源码:
import java.awt.*;
import java.awt.Event.*;
import java.applet.Applet;
public class huafangyuan_07 extends Applet implements MouseListener {
int left =-1,right = -1,x=-1,y=-1;/////////////////左右用于记录鼠标左右键,x,y记录鼠标位置
public void init(){
setBackground(Color.BLACK);
addMouseListener(this);
}
public void paint(Graphics g){
if(left == 1){
g.drawOval(x, y, 20, 20);
this.setBackground(Color.green);
}
else if(right == 1){
g.drawRect(x, y, 20, 20);
this.setBackground(Color.red);
}
}
public void mouseClicked(MouseEvent e){
x = e.getX();
y = e.getY();
if(e.getModifiers() == InputEvent.BUTTON1_MASK){
left =1;
right = -1;
repaint();
}
elde if(e.getModifiers() == InputEvent.BUTTON3_MASK){
right = 1;
left = -1;
repaint();
}
}
public void mouseExited(MouseEvent e){
left = -1;right = -1;
repaint();
}
public void mouseReleased(MouseEvent e){
}
public void mouseEntered(MouseEvent e){
}
public void mousepressed(MouseEvent e){
}
}
烦请指正问题出在哪?百般感谢!!! 展开
1个回答
2013-04-16
展开全部
public void paint(Graphics g){
super.paint(g);
if(left == 1){
试试添加一行
super.paint(g);
if(left == 1){
试试添加一行
追问
不好意思,问题解决了,其中就几个大小写错了,还有就是把else写成了elde.不过谢啦.....
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询