Ciao a tutti! Ho un problema con una JSlider, in pratica utilizzando il metodo "addChangeListener( )"
gli passo come parametro una istanza della mia classe "MyListener" che implementa "ActionListener, MouseListener, KeyListener, ChangeListener" ( voglio gestire gli eventi tramite un unica classe). Il problema è che la JSlider non genera nessun evento, ho provato tramite debug a mettere dei breakpoint dentro al metodo "stateChanged(ChangeEvent e)" ma niente da fare...pur spostando la JSlider non produce nessun evento e non entro dentro a quest'ultimo metodo...Qualcuno sà darmi qualche consiglio a riguardo. Vi allego la parte di codice interessata.
this.slider = new JSlider(JSlider.VERTICAL,0,12,6);
this.slider.setPreferredSize(new Dimension(getInt("20"), getInt("60")));
this.slider.addChangeListener(this.listener);
private class MyListener implements ActionListener, MouseListener, KeyListener, ChangeListener{
final JFileChooser fileChooser = new JFileChooser("D:\\");
private static final String SCORE = "-";
private static final int INVIO = 10;
private static final int DOUBLE = 2;
public void actionPerformed(final ActionEvent event) {
if (event.getActionCommand().equals(Const.Import.name())) {
if (getPlayer().getSongs().size() > getInt("0")) {
getPlay().setIcon(getImage().getImageIcon(Const.Play.name()));
getPlay().setActionCommand(Const.Play.name());
}
fileChooser.setMultiSelectionEnabled(true);
fileChooser.setAutoscrolls(true);
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
final Integer sel = fileChooser.showOpenDialog(frame);
if (sel.equals(JFileChooser.APPROVE_OPTION)) {
final File[] songs = fileChooser.getSelectedFiles();
if (getPlayer().getSongs().size() > getInt("0")) {
listModel.clear();
}
getPlayer().readMP3toDir(songs);
final List<String> names = getPlayer().getAllSongsNames();
for (final String name : names) {
listModel.addElement(name);
}
}
}
if (event.getActionCommand().equals(Const.New.name())) {
final int[] index = list.getSelectedIndices();
if (index.length > getInt("0")) {
final List<String> pathPL = new ArrayList<>(index.length);
for (final int idx : index) {
pathPL.add(getPlayer().getSongs().get(idx));
}
fileChooser.setFileFilter(new TxtFileFilters());
fileChooser.setAutoscrolls(true);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
final Integer select = fileChooser.showSaveDialog(frame);
if (select.equals(JFileChooser.APPROVE_OPTION)) {
try {
getPlayer().savePlayList(fileChooser.getSelectedFile().getAbsolutePath(), pathPL);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
if (event.getActionCommand().equals(Const.Load.name())) {
fileChooser.setFileFilter(new TxtFileFilters());
fileChooser.setAutoscrolls(true);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
final Integer select = fileChooser.showOpenDialog(frame);
if (select.equals(JFileChooser.APPROVE_OPTION)) {
getPlayer().loadPlayList(fileChooser.getSelectedFile().getAbsolutePath());
for (final String name: getPlayer().getAllSongsNames()) {
listModel.addElement(name);
}
}
}
if (event.getActionCommand().equals(Const.ChangeUI.name())) {
new SimplyGUI(getCurrIstance(), getPlayer());
setVisible();
}
if (event.getActionCommand().equals(Const.YouTube.name())) {
if (getPlayer().getSongs().size() > getInt("0")) {
final String artist = getPlayer().getSongInfo().get(AdvancedPlayerImpl.ARTIST);
final String title = getPlayer().getSongInfo().get(AdvancedPlayerImpl.TITLE);
if (!artist.equals(SCORE) && !title.equals(SCORE)) {
youTube.openYouTube(artist + " " + title);
} else {
youTube.openYouTube(getPlayer().getFileName());
}
}
}
}
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == DOUBLE) {
if (getPlayer().isPlayFlag()) {
getPlayer().stops();
if (getPlayer().isPauseFlag()) {
getPlayer().setPause();
}
}
getPlayer().setIndex(list.getSelectedIndex());
list.setSelectedIndex(getPlayer().getIndex());
getPlay().setIcon(getImage().getImageIcon(Const.Pause.name()));
getPlayer().play();
}
}
@Override
public void mousePressed(final MouseEvent e) {
}
@Override
public void mouseReleased(final MouseEvent e) {
}
@Override
public void mouseEntered(final MouseEvent e) {
}
@Override
public void mouseExited(final MouseEvent e) {
}
@Override
public void keyTyped(final KeyEvent e) {
}
@Override
public void keyPressed(final KeyEvent e) {
if (e.getKeyCode() == INVIO) {
getPlayer().searchSong(textField.getText());
}
}
@Override
public void keyReleased(final KeyEvent e) {
}
@Override
public void stateChanged(ChangeEvent e) {
if (slider.getValue() == getInt("0") && !slider.getValueIsAdjusting()) {
vol.setIcon(getImage().getImageIcon(Const.Volume.name()));
} else if (slider.getValue() > getInt("0") && slider.getValue() <= getInt("4")) {
vol.setIcon(getImage().getImageIcon(Const.Volume.name() + getInt("1")));
} else if (slider.getValue() > getInt("4") && slider.getValue() <= getInt("8")) {
vol.setIcon(getImage().getImageIcon(Const.Volume.name() + getInt("2")));
} else {
vol.setIcon(getImage().getImageIcon(Const.Volume.name() + getInt("3")));
}
}
}