Listing 1 defines and registers an ActionListener on the Choose Color button.
Listing 1. Event handler for the Choose Color button. |
---|
chooseButton.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ Color selColor = JColorChooser.showDialog( chooseButton,"Choose color",new Color( redInt,greenInt,blueInt)); if(selColor != null){ //Don't change the color if the user cancels // out. redField.setText("" + selColor.getRed()); greenField.setText( "" + selColor.getGreen()); blueField.setText("" + selColor.getBlue()); }//end if }//end action performed }//end new ActionListener );//end addActionListener |
File: ao.htm | [Next] | [Prev] |