/** * Handle action events coming from the buttons. * * @param evt, the associated ActionEvent. */ public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if (source instanceof JButton) { if (source == pbSave) { chosen = tcc.getColor(); onCancel(); } else { onCancel(); } } }
/** * Display a dialog which can be used to select a color * * @param dialogTitle * @param defaultColor The currently selected color * @return The color the user selected, or null if none/cancelled */ public static Color showColorChooserDialog(String dialogTitle, Color defaultColor) { Color color = null; JColorChooser chooser = new JColorChooser(); chooser.setColor(defaultColor); while (true) { int response = JOptionPane.showConfirmDialog( IGV.getMainFrame(), chooser, dialogTitle, JOptionPane.OK_CANCEL_OPTION); if ((response == JOptionPane.CANCEL_OPTION) || (response == JOptionPane.CLOSED_OPTION)) { return null; } color = chooser.getColor(); if (color == null) { continue; } else { break; } } return color; }
/** * <br> * 方法说明:事件监听。用户选择颜色触发 <br> * 输入参数:ChangeEvent e 用户选择事件 <br> * 返回类型: */ public void stateChanged(ChangeEvent e) { Color newColor = tcc.getColor(); // 获取用户选择的颜色 banner.setForeground(newColor); }
public void actionPerformed(ActionEvent e) { color = chooser.getColor(); }
/** Action listener for the OK button in the color chooser. */ public void actionPerformed(ActionEvent e) { // ok button in color chooser was pressed. this.setColor(colorChooser.getColor()); super.fireActionPerformed(e); }