Amigo, obrigado pela pronta ajuda, poder mostrar o código, sem problema, vou mandar e qualquer outra coisa que queira é só falar, gostaria de dizer que esse é meu último problema para terminar o programa.
Conforme passei acima, o método, lê um arquivo.txt (Uma musica com notas musicais acima, como mostro abaixo.
O método só lê as linhas com as notas musicais, a letra da musica ele pula e mostra esta nota em uma Label.
Eu gostaria de fazer um código que quando chegasse na última linha mostrada em um JtextPane que eu erradamente coloquei o nome da variável de (txtareamus), depois eu conserto isso, a barra de rolagem descesse para que eu acompanhasse o resto da musica e se acaso a letra for muito grande, descesse atéw a metade e depois até o fim, fui claro ? Caso não, tento te explicar de novo. Segue abaixo o código.
package Formularios;
import Classes.Sonumeros;
import static Formularios.FrmMusicaPlayViolao.current;
import static Formularios.FrmVisMusicas.txtpmusica;
import java.awt.Color;
import java.awt.Image;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
class Cifra {
final String name;
final int inicio;
final int fim;
Cifra(String name, int inicio, int fim) {
this.name = name;
this.inicio = inicio;
this.fim = fim;
}
}
public class FrmMusicaPlay extends javax.swing.JInternalFrame {
String caminhoDasMusicas = "C:\\MUSIC PLAY\\MusicasTeclado\\";
String caminhoDasNotas = "C://MUSIC PLAY//NotasTeclado//";
String flag;
int cont = 0;
boolean clicado;
Pattern p = Pattern.compile("[ABCDEFGabcdefgMm()[telefone removido]/_dim#b°+]+");
List<Cifra> cifras = new ArrayList<>();
static int current = 0;
Cifra c;
private Object e;
public FrmMusicaPlay() {
initComponents();
txttempo.setDocument(new Sonumeros());
try {
List<String> lines = new ArrayList<>();
BufferedReader ler = new BufferedReader(new InputStreamReader(
new FileInputStream(caminhoDasMusicas + txtpmusica.getText() + ".txt"), "UTF-8"));
String lin = ler.readLine();
int offset = 0;
int line = 0;
int i = 0;
while (lin != null) {
lines.add(lin);
if (line % 2 == 0) {
Matcher m = p.matcher(lin);
while (m.find()) {
cifras.add(new Cifra(m.group(), m.start() + offset, m.end() + offset));
}
}
offset += lin.length() + 1;
i++;
line++;
lin = ler.readLine();
}
txtareamus.setText(String.join("\n", lines));
} catch (Exception e) {
System.out.println("erroo na leitura: " + e.getMessage());
}
txtareamus.setCaretPosition(0);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Btnsair = new javax.swing.JButton();
btniniciar = new javax.swing.JButton();
lblnota = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txtposicao = new javax.swing.JTextField();
txttempo = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
btnparar = new javax.swing.JButton();
btncontinuar = new javax.swing.JButton();
txttempopausa = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
txtareamus = new javax.swing.JTextPane();
Btnsair.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
Btnsair.setForeground(java.awt.Color.red);
Btnsair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagem/Sai_Peq.png"))); // NOI18N
Btnsair.setText("Sair");
Btnsair.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnsairActionPerformed(evt);
}
});
btniniciar.setFont(new java.awt.Font("Arial", 1, 22)); // NOI18N
btniniciar.setForeground(java.awt.Color.blue);
btniniciar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagem/musica.png"))); // NOI18N
btniniciar.setText("Iniciar");
btniniciar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btniniciarActionPerformed(evt);
}
});
lblnota.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.red, 2));
jLabel1.setFont(new java.awt.Font("Arial", 1, 22)); // NOI18N
jLabel1.setForeground(java.awt.Color.blue);
jLabel1.setText("Nota :");
jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabel1MouseClicked(evt);
}
});
jLabel10.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
jLabel10.setForeground(java.awt.Color.red);
jLabel10.setText("TOCAR MÚSICAS");
jLabel2.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jLabel2.setForeground(java.awt.Color.blue);
jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagem/dj_peq.png"))); // NOI18N
jLabel2.setText("Música :");
txtposicao.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
txtposicao.setForeground(java.awt.Color.red);
txttempo.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel3.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jLabel3.setForeground(java.awt.Color.red);
jLabel3.setText("Tempo da Música (Seg)");
btnparar.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
btnparar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagem/parar2.png"))); // NOI18N
btnparar.setText("Pausa");
btnparar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnpararActionPerformed(evt);
}
});
btncontinuar.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
btncontinuar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagem/Nota.png"))); // NOI18N
btncontinuar.setText("Continuar");
btncontinuar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btncontinuarActionPerformed(evt);
}
});
txttempopausa.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
txttempopausa.setForeground(java.awt.Color.blue);
jLabel4.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jLabel4.setForeground(java.awt.Color.red);
jLabel4.setText("Tempo da Pausa (Seg)");
txtareamus.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.red, 2));
txtareamus.setFont(new java.awt.Font("Arial", 1, 20)); // NOI18N
txtareamus.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
txtareamusMouseEntered(evt);
}
public void mousePressed(java.awt.event.MouseEvent evt) {
txtareamusMousePressed(evt);
}
});
jScrollPane1.setViewportView(txtareamus);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 825, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(txtposicao, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(188, 188, 188))
.addGroup(layout.createSequentialGroup()
.addGap(515, 515, 515)
.addComponent(Btnsair))
.addGroup(layout.createSequentialGroup()
.addGap(289, 289, 289)
.addComponent(txttempo, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(lblnota, javax.swing.GroupLayout.PREFERRED_SIZE, 602, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(211, 211, 211)
.addComponent(jLabel3)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(285, 285, 285)
.addComponent(txttempopausa, javax.swing.GroupLayout.PREFERRED_SIZE, 48,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(29, 29, 29)
.addComponent(btnparar)
.addGap(69, 69, 69)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel4)
.addGap(199, 199, 199))
.addGroup(layout.createSequentialGroup()
.addComponent(btniniciar, javax.swing.GroupLayout.PREFERRED_SIZE, 160,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btncontinuar)
.addGap(17, 17, 17))))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtposicao, javax.swing.GroupLayout.PREFERRED_SIZE, 67,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(35, 35, 35)
.addComponent(lblnota, javax.swing.GroupLayout.PREFERRED_SIZE, 250,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22,
Short.MAX_VALUE)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txttempo, javax.swing.GroupLayout.PREFERRED_SIZE, 37,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btniniciar, javax.swing.GroupLayout.PREFERRED_SIZE, 42,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnparar, javax.swing.GroupLayout.PREFERRED_SIZE, 45,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btncontinuar, javax.swing.GroupLayout.PREFERRED_SIZE, 44,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49,
Short.MAX_VALUE)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Btnsair, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addComponent(txttempopausa, javax.swing.GroupLayout.PREFERRED_SIZE,
36, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27))))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2))
.addComponent(jLabel10))
.addGap(18, 18, 18)
.addComponent(jScrollPane1)))
.addContainerGap())
);
setBounds(3, 0, 1499, 723);
}// </editor-fold>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void BtnsairActionPerformed(java.awt.event.ActionEvent evt) {
txttempo.setText("0");
this.dispose();
}
boolean isRunning = false;
ScheduledThreadPoolExecutor executor;
private void btniniciarActionPerformed(java.awt.event.ActionEvent evt) {
if (isRunning) {
executor.shutdown();
isRunning = false;
}
executor = new ScheduledThreadPoolExecutor(1);
isRunning = true;
executor.scheduleAtFixedRate(() -> {
c = cifras.get(current);
try {
txtareamus.getHighlighter().removeAllHighlights();
txtareamus.getHighlighter().addHighlight(c.inicio, c.fim,
new DefaultHighlighter.DefaultHighlightPainter(Color.cyan));
} catch (BadLocationException ex) {
Logger.getLogger(FrmMusicaPlay.class.getName()).log(Level.SEVERE, null, ex);
}
if(current ==24) {
JOptionPane.showMessageDialog(null, "Passei na linha 24 !"); OBS : Aqui eu sei em que
linha da leitura estou e posso aplicar o código para descer a barra de rolagem
}
String nova = c.name.replace("/", "_");
txtposicao.setText(nova);
ImageIcon imageIcon = new ImageIcon(new ImageIcon(caminhoDasNotas +
txtposicao.getText() + ".jpg").getImage().getScaledInstance(599, 243,
Image.SCALE_DEFAULT));
lblnota.setIcon(imageIcon);
current++;
}, 0, Integer.parseInt(txttempo.getText()), TimeUnit.SECONDS);
String selecionado = txtareamus.getSelectedText();
}
private void btnpararActionPerformed(java.awt.event.ActionEvent evt) {
flag = txttempo.getText();
String p = txttempopausa.getText();
txttempo.setText(p);
}
private void btncontinuarActionPerformed(java.awt.event.ActionEvent evt) {
String c;
c = flag;
txttempo.setText(c);
}
private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {
}
private void txtareamusMousePressed(java.awt.event.MouseEvent evt) {
String selecionado = txtareamus.getSelectedText();
txtposicao.setText(selecionado);
ImageIcon imageIcon = new ImageIcon(new ImageIcon("C://MUSIC PLAY//NotasTeclado//"+
txtposicao.getText()+ ".jpg").getImage().getScaledInstance(599,243,Image.SCALE_DEFAULT));
lblnota.setIcon(imageIcon);
}
private void txtareamusMouseEntered(java.awt.event.MouseEvent evt) {
}
// Variables declaration - do not modify
private javax.swing.JButton Btnsair;
private javax.swing.JButton btncontinuar;
private javax.swing.JButton btniniciar;
private javax.swing.JButton btnparar;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lblnota;
private javax.swing.JTextPane txtareamus;
private javax.swing.JTextField txtposicao;
private javax.swing.JTextField txttempo;
private javax.swing.JTextField txttempopausa;
// End of variables declaration
private void stop() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}
private void interrupt() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of
generated
methods, choose Tools | Templates.
}
private void If(boolean b) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}
private void setCaretPosition(int length) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}
}