CSDN博客

img tairui1

新手上路多多帮忙

发表于2004/7/3 17:25:00  344人阅读

//新手上路多多帮忙

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class listener extends Applet implements ActionListener,
                                                MouseMotionListener{
                               
 int x=-1,y=-1,rubber=0,clear=0;
 Color c = new Color(255,0,0);
 int con=3;
 Button redbutton,bluebutton,greenbutton,rubberbutton,clearbutton;
 public void init()
 {
  addMouseMotionListener(this);
  redbutton = new Button("红色");
  bluebutton = new Button("蓝色");
  greenbutton = new Button("绿色");
  rubberbutton = new Button("橡皮");
  clearbutton = new Button("清除");
  add(redbutton);
  add(bluebutton);
  add(greenbutton);
  add(rubberbutton);
  add(clearbutton);
  redbutton.addActionListener(this);
  bluebutton.addActionListener(this);
  greenbutton.addActionListener(this);
  rubberbutton.addActionListener(this);
  clearbutton.addActionListener(this);
  setSize(640,480);
  
  
  
  
  }
 //paint方法
 public void paint(Graphics g)
 {
  if(rubber==0&&clear==0)
  {
   g.setColor(c);
   g.fillOval(x,y,con,con);
   
   
   }//end of if
  else if (rubber==1&&clear==0)
  {
   g.clearRect(x,y,10,10);
   } 
  else if(rubber==0&&clear==1)
  {
   g.clearRect(0,0,getSize().width,getSize().height);
   } 
  
  } 
 public void mouseDragged(MouseEvent e)
 {
  x=(int)e.getX();
  y=(int)e.getY();
  repaint();
  
  }
 public void  mouseMove(MouseEvent e)
 {
  
 }
  public void  update(Graphics g)
  {
   paint(g);
   }
  public void actionPerformed(ActionEvent e)
  {
   if(e.getSource()==redbutton)
   {
    rubber=clear=0;
    c=new Color(255,0,0);
    }
   else if(e.getSource()==bluebutton)
   {
    rubber=clear=0;
    c=new Color(0,0,255);
    }
   else if(e.getSource()==greenbutton)
   {
    rubber=clear=0;
    c = new Color(0,255,0);
    }
   else if(e.getSource()==rubberbutton)
   {
    rubber=1;
    clear=0;
    }
   else if(e.getSource()==clearbutton)
   {
    rubber=0;
    clear=1;
    repaint();
   } 
     
 } 

//错误提示

F:/学校教学课件/JAVA/java/listener.java:4: listener
is not abstract and does not override abstract method mouseReleased(java.awt.event.MouseEvent)
in java.awt.event.MouseListener
public class listener extends Applet implements ActionListener,

0 0

相关博文

我的热门文章

img
取 消
img