加一句
import javax.swing.event.*;

解决方案 »

  1.   

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;public class Second extends JFrame {
       private int pointCount = 0;
       private Point points[] = new Point[ 1000 ]; 
       private JList colorList;
        private Container container;
    int currentColor ;
       private final String colorNames[] = { "Black", "Blue", "Cyan",
          "Dark Gray", "Gray", "Green", "Light Gray", "Magenta",
          "Orange", "Pink", "Red", "White", "Yellow" };
       private final Color colors[] = { Color.black, Color.blue, Color.cyan,
          Color.darkGray, Color.gray, Color.green, Color.lightGray, Color.magenta,   
          Color.orange, Color.pink, Color.red, Color.white, Color.yellow };
       public Second()
       { 
      super( "My simple Second program" );
          container = getContentPane();
          container.setLayout( new FlowLayout() );
          colorList = new JList( colorNames );
          colorList.setVisibleRowCount( 5 );
          colorList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
          container.add( new JScrollPane( colorList ) );
          colorList.addListSelectionListener( new CLI());        addMouseMotionListener(  new MouseMotionAdapter() 
            {  
                public void mouseDragged( MouseEvent event )
                { if ( pointCount < points.length ) 
                    { points[ pointCount ] = event.getPoint();
                       ++pointCount;
                       repaint();   }    }    }
         ); 
        setSize( 300, 150 );
    setVisible( true );  
       }   
       public void paint( Graphics g )
       { super.paint( g ); 
          g.setColor(colors[1]);
          for ( int i = 0; i < points.length && points[ i ] != null; i++ )
             g.fillOval( points[ i ].x, points[ i ].y, 4, 4 );
     
       }
       public static void main( String args[] )
       { 
       Second application = new Second();
       application.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
           application.addWindowListener( new WindowAdapter()
             { public void windowClosing(WindowEvent e)
                { System.exit(0);   }
              });
       }
       class CLI implements ListSelectionListener {
        public void valueChanged( ListSelectionEvent event )
               {
    //currentColor=colors[colorList.getSelectedIndex()];
               }
              }
       }