import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.net.URL;
import javazoom.jlgui.basicplayer.BasicPlayer;
import javazoom.jlgui.basicplayer.BasicPlayerException;
public class InterfaceEfecto extends javax.swing.JFrame {
public InterfaceEfecto() {
initComponents();
introArray("efecto0.mp3", 0);
introArray("efecto1.mp3", 1);
introArray("efecto2.mp3", 2);
introArray("efecto3.mp3", 3);
introArray("efecto4.mp3", 4);
introArray("efecto5.mp3", 5);
introArray("efecto6.mp3", 6);
introArray("efecto7.mp3", 7);
introArray("efecto8.mp3", 8);
introArray("efecto9.mp3", 9);
jListCanciones.setListData(lista);
jListCanciones.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
jLabelRuta.setText("Ruta: " + efecto[jListCanciones.getSelectedIndex()]);
}
});
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jListCanciones = new javax.swing.JList<>();
jButtonAvanzar = new javax.swing.JButton();
jButtonReproducir = new javax.swing.JButton();
jButtonRetroceder = new javax.swing.JButton();
jLabelRuta = new javax.swing.JLabel();
jLabelfondo = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jScrollPane1.setViewportView(jListCanciones);
getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 10, 220, 370));
jButtonAvanzar.setText("Arriba");
jButtonAvanzar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonAvanzarActionPerformed(evt);
}
});
getContentPane().add(jButtonAvanzar, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 20, -1, -1));
jButtonReproducir.setText("Reproducir");
jButtonReproducir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonReproducirActionPerformed(evt);
}
});
getContentPane().add(jButtonReproducir, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 160, -1, -1));
jButtonRetroceder.setText("Abajo");
jButtonRetroceder.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonRetrocederActionPerformed(evt);
}
});
getContentPane().add(jButtonRetroceder, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 350, -1, -1));
jLabelRuta.setFont(new java.awt.Font("Source Code Pro Black", 1, 10)); // NOI18N
jLabelRuta.setForeground(new java.awt.Color(255, 255, 255));
jLabelRuta.setText("Ruta:");
getContentPane().add(jLabelRuta, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 400, -1, -1));
jLabelfondo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fondo/music1.png"))); // NOI18N
getContentPane().add(jLabelfondo, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 660, -1));
pack();
}// </editor-fold>
private void jButtonAvanzarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
seleccion(-1);
}
private void jButtonReproducirActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (jListCanciones.getSelectedIndex()!=-1){
int posicion = jListCanciones.getSelectedIndex();
try{
player.open(efecto[posicion]);
player.play();
}catch(BasicPlayerException ex){
System.out.println("Error el archivo no existe o la ruta no es correcta...");
}
}
}
private void jButtonRetrocederActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
seleccion(+1);
}
public void introArray(String ruta,int posicion){
URL rut = getClass().getResource("efecto/"+ruta);
efecto[posicion]=rut;
File file = new File(ruta);
String eFFect = file.getName();
lista[posicion]=eFFect;
}
public void seleccion(int lo){
if (jListCanciones.getSelectedIndex()!=-1){
jListCanciones.setSelectedIndex(jListCanciones.getSelectedIndex()+lo);
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new InterfaceEfecto().setVisible(true);
}
});
}
private URL efecto[]= new URL[10];
private String lista[] = new String[10];
private BasicPlayer player = new BasicPlayer();
// Variables declaration - do not modify
private javax.swing.JButton jButtonAvanzar;
private javax.swing.JButton jButtonReproducir;
private javax.swing.JButton jButtonRetroceder;
private javax.swing.JLabel jLabelRuta;
private javax.swing.JLabel jLabelfondo;
private javax.swing.JList<String> jListCanciones;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration
}
Comentarios sobre la versión: 1 (0)
No hay comentarios