`
laoyuko
  • 浏览: 855 次
  • 性别: Icon_minigender_1
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

编写工具栏画图时出现一个问题谁能帮我解决一下。先谢谢啦!...

阅读更多
错误为:
  C:\Documents and Settings\Administrator\桌面\ButtonClick.java:13: ButtonClick1 is not abstract and does not override abstract method mouseExited(java.awt.event.MouseEvent) in java.awt.event.MouseListener
   class ButtonClick1 extends JFrame implements ActionListener, MouseListener



       import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  public class ButtonClick
  {
  public static void main(String[] args)
  {
  ButtonClick1 frame=new ButtonClick1();
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.show();
  }
  }
   class ButtonClick1 extends JFrame implements ActionListener, MouseListener
  {
  private String a[]={“三角形“,“四边形“,“五边形“,“选色“};
  private JButton button[]=new JButton[a.length];
  private Container contentpane;
  private JPanel buttonpanel;
  private JToolBar jtoolbar;
  private Color color=Color.lightGray;
  private int k;
  private float x,y,x1,y1;
  
  public ButtonClick1()
  {
   setTitle(“hua tu“);
   setSize(300,400);
   buttonpanel=new JPanel();
   contentpane=getContentPane();
   jtoolbar=new JToolBar(“工具栏“);
   // j.setFloatable();
   for (int i=0;i<a.length;i++)
   {
   button[i]=new JButton(a[i]);
   button[i].addActionListener(this);
  
   jtoolbar.add(button[i]);
  
   }
  
   buttonpanel.add(jtoolbar);
   contentpane.add(buttonpanel);
   addMouseListener(this);
  
   }
   public void actionPerformed (ActionEvent e)
   {
   for(int i=0;i<2;i++)
  
   if(e.getSource()==button[i])
   k=i+3;
   if(e.getSource()==button[3])
   {
   color=JColorChooser.showDialog(this,“选色“,color);
   contentpane.setForeground(color);
   contentpane.repaint();
   }
   }
   public void mousePressed(MouseEvent e)
   {
   x=e.getX();
   y=e.getY();
   }
   public void mouseReleased(MouseEvent e)
   {
   x1=e.getX();
   y1=e.getY();
   repaint();
   }
   public void paint(Graphics g)
   {
   int xvalues[];
   int yvalues[];
   xvalues[0]=(int)x;
   yvalues[0]=(int)y;
   xvalues[k-1]=(int)x1;
   yvalues[k-1]=(int)y1;
   for(int i=1; i<k-1;i++)
   {
   xvalues[i]=(int)((Math.random())*(x1-x)/2);
   yvalues[i]=(int)((Math.random())*(y1-y)/2);
   }
   Polygon poly=new Polygon(xvalues,yvalues,k);
   g.drawPolygon(poly);
   }
  }
  
分享到:
评论
Global site tag (gtag.js) - Google Analytics