2011-09-04 53 views
-4

可能重复:
What does the "Multiple markers" mean?Java,这条线上的多重标记是什么意思?

package test2; 
import java.awt.*; 
import java.awt.event.*; 


public class MyDrawing3Demo extends Frame{ 

    Panel p1,p2; 
    Button red,green,blue,large,small,clear,allClear; 
    MyCanvas2 can; 
    public MyDrawing3Demo(){ 
     super("::MyDrawing3Demo::"); 

     p1 = new Panel(); 
     p1.setBackground(Color.blue); 
     add(p1,"North"); 

     p2 = new Panel(){ 
      public Insets getInsets(){ 
       return new Insets(40,20,20,20); 
      } 
     }; 
     p2.setBackground(Color.darkGray); 
     add(p2,"Center"); 

     p1.add(red = new Button("Red")); 
     p1.add(green = new Button("Green")); 
     p1.add(blue = new Button("Blue")); 
     p1.add(large = new Button("Large")); 
     p1.add(small = new Button("Small")); 
     p1.add(clear = new Button("Clear")); 
     p1.add(allClear = new Button("All Clear")); 

     MyHandler2 my = new MyHandler2(); // ERROR! Multiple Markers at this line 

     red.addActionListener(my); 
     green.addActionListener(my); 
     blue.addActionListener(my); 
     large.addActionListener(my); 
     small.addActionListener(my); 
     clear.addActionListener(my); 
     allClear.addActionListener(my); 

     can = new MyCanvas2(); 
     can.setSize(300,300); 
     can.setBackground(Color.white); 
     p2.add(can); 


     can.addMouseMotionListener(my); 

     addWindowListener(new WindowAdapter(){ 
      public void windowClosing(WindowEvent e){ 
       System.exit(0); 
      } 
     }); 


     class MyHandler2 extends MouseMotionAdapter implements ActionListener 
     { 
      public void mouseDragged(MouseEvent e){ 
       can.x = e.getX(); 
       can.y = e.getY(); 
       can.repaint(); 
      } 
      public void actionPerformed(ActionEvent e){ 
       Object o = e.getSource(); 
       if(o == red){ 
        can.cr = Color.red; 
       }else if(o == blue){ 
        can.cr = Color.blue; 
       }else if(o == green){ 
        can.cr = Color.green; 
       }else if(o == large){ 
        if(can.w <20){ 
         can.w++; 
         can.h++; 
        } 
       }else if(o == small){ 
        if(can.w >2){ 
         can.w--; 
         can.h--; 
        } 
       }else if(o == clear){ 
        can.cr = can.getBackground(); 
       }else if(o == allClear){ 
        can.flag = 1; 
        can.repaint(); 
       } 
      } 
     } 

    } 

    public static void main(String[] args){ 
     MyDrawing3Demo d = new MyDrawing3Demo(); 
     d.setSize(500,500); 
     d.setVisible(true); 
    } 
} 

class MyCanvas2 extends Canvas{ 
    /** 
    * 
    */ 
    private static final long serialVersionUID = -2856701740289022957L; 
    int x=-13,y=-13,w=7,h=7; 
    Color cr = Color.black; 
    int flag = 0; 
    public void update(Graphics g){ 
     paint(g); 
    } 
    public void paint(Graphics g){ 
     if(flag == 0){ 
      g.setColor(cr); 
      g.fillOval(x,y,w,h); 
     }else if (flag == 1){ 
      g.clearRect(0,0,300,300); 
      flag = 0; 
     } 
    } 
} 

回答

2

这意味着这条线上有两个错误。这是因为你使用的类型是编译器不知道的。您的类MyHandler2的声明是在构造函数内完成的,您应该将其移到外面。也就是说,在主要宣布之前将主要动作移动到正确的位置。

+0

非常感谢你! –

2

“多个标记” 距离你的IDE(NetBeans中,可能的话)告诉你它有超过一两件事要说消息关于这条线。您需要点击标记以获取实际的错误消息。