import java.util.*;
public class Teclado extends javax.swing.JFrame{
int teclas[] = new int[99999];
double tempoPressionado[] = new double[99999];
int qtdElementos=0;
String filetxt = "notas.txt";
long tempoSemTocarInicial=0, tempoSemTocarFinal, tempoSemTocarTotal;
long tempoApertadoDo, tempoSoltoDo, tempoTotalDo;
long tempoApertadoRe, tempoSoltoRe, tempoTotalRe;
long tempoApertadoMi, tempoSoltoMi, tempoTotalMi;
long tempoApertadoFa, tempoSoltoFa, tempoTotalFa;
long tempoApertadoSol, tempoSoltoSol, tempoTotalSol;
long tempoApertadoLa, tempoSoltoLa, tempoTotalLa;
long tempoApertadoSi, tempoSoltoSi, tempoTotalSi;
String texto[] = new String[999];
File_IO readWrite = new File_IO();
Scanner keyboard = new Scanner(System.in);
public Teclado() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setBackground(new java.awt.Color(255, 255, 255));
jButton1.setText("Dó");
jButton1.setMaximumSize(new java.awt.Dimension(73, 23));
jButton1.setMinimumSize(new java.awt.Dimension(73, 23));
jButton1.setPreferredSize(new java.awt.Dimension(73, 23));
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jButton1MousePressed(evt);
}
public void mouseReleased(java.awt.event.MouseEvent evt) {
jButton1MouseReleased(evt);
}
});
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setBackground(new java.awt.Color(255, 255, 255));
jButton2.setText("Ré");
jButton2.setMaximumSize(new java.awt.Dimension(73, 23));
jButton2.setMinimumSize(new java.awt.Dimension(73, 23));
jButton2.setPreferredSize(new java.awt.Dimension(73, 23));
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jButton2MousePressed(evt);
}
public void mouseReleased(java.awt.event.MouseEvent evt) {
jButton2MouseReleased(evt);
}
});
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setBackground(new java.awt.Color(255, 255, 255));
jButton3.setText("Mi");
jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jButton3MousePressed(evt);
}
public void mouseReleased(java.awt.event.MouseEvent evt) {
jButton3MouseReleased(evt);
}
});
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setBackground(new java.awt.Color(255, 255, 255));
jButton4.setText("Fa");
jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jButton4MousePressed(evt);
}
public void mouseReleased(java.awt.event.MouseEvent evt) {
jButton4MouseReleased(evt);
}
});
jButton5.setBackground(new java.awt.Color(255, 255, 255));
jButton5.setText("Sol");
jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jButton5MousePressed(evt);
}
public void mouseReleased(java.awt.event.MouseEvent evt) {
jButton5MouseReleased(evt);
}
});
jButton6.setBackground(new java.awt.Color(255, 255, 255));
jButton6.setText("La");
jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jButton6MousePressed(evt);
}
public void mouseReleased(java.awt.event.MouseEvent evt) {
jButton6MouseReleased(evt);
}
});
jButton7.setBackground(new java.awt.Color(255, 255, 255));
jButton7.setText("Si");
jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jButton7MousePressed(evt);
}
public void mouseReleased(java.awt.event.MouseEvent evt) {
jButton7MouseReleased(evt);
}
});
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});
jButton8.setText("End");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton8ActionPerformed(evt);
}
});
jButton10.setText("Stop");
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton10ActionPerformed(evt);
}
});
jButton11.setText("Start");
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton11ActionPerformed(evt);
}
});
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()
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton11)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton8)))
.addGap(66, 66, 66))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE)
.addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton8)
.addComponent(jButton10)
.addComponent(jButton11))
.addGap(20, 20, 20))
);
pack();
}
private void passarParaTxt(int elementos)
{
readWrite.openOutputFile(filetxt);
for(int i = 0;i<elementos;i++)
{
readWrite.writeOutputLine(""+teclas[i]);
readWrite.writeOutputLine(""+tempoPressionado[i]+"");
}
readWrite.closeOutputFile();
}
private void onExit()
{
readWrite.openInputFile("Hack/Hack.ino");
int j=0;
while(readWrite.hasInputLine())
{
texto[j] = readWrite.readInputLine();
System.out.println(texto[j]);
j++;
}
readWrite.closeInputFile();
for(int i=0;i<qtdElementos;i++)
{
if(i==0)
{
texto[1]= (teclas[i]+"");
}
else{
texto[1]= (texto[1]+" ,"+ teclas[i]);
}
}
for(int i=0;i<qtdElementos;i++)
{
if(i==0)
{
texto[4]= (tempoPressionado[i]+"");
}
else{
texto[4]= (texto[4]+" ,"+ tempoPressionado[i]);
}
}
texto[6] = ("int qtdElementos ="+ qtdElementos+";");
readWrite.openOutputFile("Hack/Hack.ino");
j=0;
while(texto[j]!=null)
{
readWrite.writeOutputLine(texto[j]);
j++;
}
readWrite.closeOutputFile();
}
private void comecarVazio()
{
tempoSemTocarInicial = System.currentTimeMillis();
}
private void terminarVazio()
{
tempoSemTocarFinal = System.currentTimeMillis();
tempoSemTocarTotal = tempoSemTocarFinal - tempoSemTocarInicial;
teclas[qtdElementos]= 0;
tempoPressionado[qtdElementos] = tempoSemTocarTotal;
qtdElementos++;
qtdElementos = checarCheio(qtdElementos);
}
private int checarCheio(int numeroDeElementos)
{
if(numeroDeElementos>=99998)
{
passarParaTxt(numeroDeElementos);
numeroDeElementos = 0;
}
return numeroDeElementos;
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
onExit();
System.exit(0);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jButton1MousePressed(java.awt.event.MouseEvent evt) {
terminarVazio();
tempoApertadoDo = System.currentTimeMillis();
}
private void jButton1MouseReleased(java.awt.event.MouseEvent evt) {
tempoSoltoDo = System.currentTimeMillis();
tempoTotalDo = tempoSoltoDo - tempoApertadoDo;
teclas[qtdElementos]= 1;
tempoPressionado[qtdElementos] = tempoTotalDo;
qtdElementos++;
qtdElementos = checarCheio(qtdElementos);
comecarVazio();
}
private void jButton2MousePressed(java.awt.event.MouseEvent evt) {
terminarVazio();
tempoApertadoRe = System.currentTimeMillis();
}
private void jButton2MouseReleased(java.awt.event.MouseEvent evt) {
tempoSoltoRe = System.currentTimeMillis();
tempoTotalRe = tempoSoltoRe - tempoApertadoRe;
teclas[qtdElementos]= 2;
tempoPressionado[qtdElementos] = tempoTotalRe;
qtdElementos++;
qtdElementos = checarCheio(qtdElementos);
comecarVazio();
}
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {
tempoSemTocarFinal = System.currentTimeMillis();
tempoSemTocarTotal = tempoSemTocarFinal - tempoSemTocarInicial;
passarParaTxt(qtdElementos);
}
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {
tempoSemTocarInicial = System.currentTimeMillis();
}
private void jButton3MousePressed(java.awt.event.MouseEvent evt) {
terminarVazio();
tempoApertadoMi = System.currentTimeMillis();
}
private void jButton3MouseReleased(java.awt.event.MouseEvent evt) {
tempoSoltoMi = System.currentTimeMillis();
tempoTotalMi = tempoSoltoMi - tempoApertadoMi;
teclas[qtdElementos]= 3;
tempoPressionado[qtdElementos] = tempoTotalMi;
qtdElementos++;
qtdElementos = checarCheio(qtdElementos);
comecarVazio();
}
private void jButton4MousePressed(java.awt.event.MouseEvent evt) {
terminarVazio();
tempoApertadoFa = System.currentTimeMillis();
}
private void jButton4MouseReleased(java.awt.event.MouseEvent evt) {
tempoSoltoFa = System.currentTimeMillis();
tempoTotalFa = tempoSoltoFa - tempoApertadoFa;
teclas[qtdElementos]= 4;
tempoPressionado[qtdElementos] = tempoTotalFa;
qtdElementos++;
qtdElementos = checarCheio(qtdElementos);
comecarVazio();
}
private void jButton5MousePressed(java.awt.event.MouseEvent evt) {
terminarVazio();
tempoApertadoSol = System.currentTimeMillis();
}
private void jButton5MouseReleased(java.awt.event.MouseEvent evt) {
tempoSoltoSol = System.currentTimeMillis();
tempoTotalSol = tempoSoltoSol - tempoApertadoSol;
teclas[qtdElementos]= 5;
tempoPressionado[qtdElementos] = tempoTotalSol;
qtdElementos++;
qtdElementos = checarCheio(qtdElementos);
comecarVazio();
}
private void jButton6MousePressed(java.awt.event.MouseEvent evt) {
terminarVazio();
tempoApertadoLa = System.currentTimeMillis();
}
private void jButton6MouseReleased(java.awt.event.MouseEvent evt) {
tempoSoltoLa = System.currentTimeMillis();
tempoTotalLa = tempoSoltoLa - tempoApertadoLa;
teclas[qtdElementos]= 6;
tempoPressionado[qtdElementos] = tempoTotalLa;
qtdElementos++;
qtdElementos = checarCheio(qtdElementos);
comecarVazio();
}
private void jButton7MousePressed(java.awt.event.MouseEvent evt) {
terminarVazio();
tempoApertadoSi = System.currentTimeMillis();
}
private void jButton7MouseReleased(java.awt.event.MouseEvent evt) {
tempoSoltoSi = System.currentTimeMillis();
tempoTotalSi = tempoSoltoSi - tempoApertadoSi;
teclas[qtdElementos]= 7;
tempoPressionado[qtdElementos] = tempoTotalSi;
qtdElementos++;
qtdElementos = checarCheio(qtdElementos);
comecarVazio();
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Teclado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Teclado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Teclado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Teclado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Teclado().setVisible(true);
}
});
}
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
}
Nenhum comentário:
Postar um comentário