Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 46 additions & 119 deletions src/bitbyte/MyJFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,21 @@
import javax.swing.JFrame;
import rtu_location.TableCableColor;
import rtu_location.TableRTU;
import utils.ListenerRaw;
import utils.MeuListener;

/**
* * @author menon
* @author menon
*/
public class MyJFrame extends javax.swing.JFrame {

public MyJFrame() {
/**
* * Creates new form MyJFrame
*/
initComponents();
btPTNO.addActionListener(new MeuListener("btPTNO", t1, t3));
btBitByte.addActionListener(new MeuListener("btBitByte", t2, t4));
btLimparTudo.addActionListener(new MeuListener("btLimparPTNO", t1, t3));
btLimparTudo.addActionListener(new MeuListener("btLimparBit", t2, t4));
//Raw
}

/**
* * This method is called from within the constructor to initialize the
* form. WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
btPTNO.addActionListener(new MeuListener("btPTNO", bitByteInput, ptnoOutput, errorLabel));
btBitByte.addActionListener(new MeuListener("btBitByte", ptnoInput, bitByteOutput, errorLabel));
btLimparTudo.addActionListener(new MeuListener("btLimparPTNO", bitByteInput, ptnoOutput, errorLabel));
btLimparTudo.addActionListener(new MeuListener("btLimparBit", ptnoInput, bitByteOutput, errorLabel));
Comment on lines +17 to +18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 | Confidence: High

The same button (btLimparTudo) is assigned two separate listeners with different opcodes, which creates unnecessary complexity. Both listeners perform essentially the same operation (clearing fields). This could be simplified by having a single listener that clears all relevant fields.

Code Suggestion:

btLimparTudo.addActionListener(e -> {
    bitByteInput.setText("");
    ptnoOutput.setText("");
    ptnoInput.setText("");
    bitByteOutput.setText("");
    errorLabel.setText("");
});

}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
Expand All @@ -39,20 +29,21 @@ private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
t1 = new javax.swing.JTextField();
bitByteInput = new javax.swing.JTextField();
btPTNO = new javax.swing.JButton();
t3 = new javax.swing.JTextField();
ptnoOutput = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
t2 = new javax.swing.JTextField();
ptnoInput = new javax.swing.JTextField();
btBitByte = new javax.swing.JButton();
t4 = new javax.swing.JTextField();
bitByteOutput = new javax.swing.JTextField();
btLimparTudo = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
ShowUTR1 = new javax.swing.JButton();
jLabel9 = new javax.swing.JLabel();
jButton_show_CColor = new javax.swing.JButton();
errorLabel = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(255, 255, 255));
Expand All @@ -74,40 +65,19 @@ private void initComponents() {
jLabel2.setText("BitByte");

btPTNO.setText("Calcular PTNO");
btPTNO.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btPTNOActionPerformed(evt);
}
});

t3.setEditable(false);
t3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
t3ActionPerformed(evt);
}
});
ptnoOutput.setEditable(false);

jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel6.setText("Conversor PTNO --> BitByte ");

jLabel3.setText("PTNO");

t2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
t2ActionPerformed(evt);
}
});

btBitByte.setText("Calcular BitByte");

t4.setEditable(false);
bitByteOutput.setEditable(false);

btLimparTudo.setText("Limpar");
btLimparTudo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btLimparTudoActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
Expand All @@ -121,21 +91,21 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bitByteInput, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btPTNO))
.addComponent(jLabel1))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(t3, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
.addComponent(t4))
.addComponent(ptnoOutput, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
.addComponent(bitByteOutput))
.addGap(57, 57, 57))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(23, 23, 23)
.addComponent(t2, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(ptnoInput, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
Expand All @@ -153,9 +123,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bitByteInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btPTNO)
.addComponent(t3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(ptnoOutput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
Expand All @@ -164,9 +134,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(t2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ptnoInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btBitByte)
.addComponent(t4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(bitByteOutput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(17, Short.MAX_VALUE))
);

Expand All @@ -181,11 +151,6 @@ public void mouseClicked(java.awt.event.MouseEvent evt) {
ShowUTR1MouseClicked(evt);
}
});
ShowUTR1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ShowUTR1ActionPerformed(evt);
}
});

jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel9.setText("Código de cores dos fios das UTRs (Preto e Branco, Coloridos, 8 ou 9 fios)");
Expand All @@ -196,11 +161,6 @@ public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton_show_CColorMouseClicked(evt);
}
});
jButton_show_CColor.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton_show_CColorActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
Expand Down Expand Up @@ -265,91 +225,60 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addGap(24, 24, 24)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(errorLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel4))
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void btLimparTudoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLimparTudoActionPerformed
}//GEN-LAST:event_btLimparTudoActionPerformed

private void t2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t2ActionPerformed
}//GEN-LAST:event_t2ActionPerformed

private void ShowUTR1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ShowUTR1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_ShowUTR1ActionPerformed

private void ShowUTR1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ShowUTR1MouseClicked
private void ShowUTR1MouseClicked(java.awt.event.MouseEvent evt) {
JFrame frame = new JFrame("Tabela de Localização das Remotas (UTR)");
TableRTU newContentPane = new TableRTU(); //Create and set up the content pane.
newContentPane.setOpaque(true); //content panes must be opaque
TableRTU newContentPane = new TableRTU();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.pack(); //Display the window.
frame.pack();
frame.setVisible(true);
}//GEN-LAST:event_ShowUTR1MouseClicked

private void jButton_show_CColorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_show_CColorActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jButton_show_CColorActionPerformed
}

private void jButton_show_CColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_show_CColorMouseClicked
private void jButton_show_CColorMouseClicked(java.awt.event.MouseEvent evt) {
JFrame frame = new JFrame("Cores de Fios (6006DC07199E)");
TableCableColor newContentPane = new TableCableColor(); //Create and set up the content pane.
newContentPane.setOpaque(true); //content panes must be opaque
TableCableColor newContentPane = new TableCableColor();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.pack(); //Display the window.
frame.setVisible(true); // TODO add your handling code here:
}//GEN-LAST:event_jButton_show_CColorMouseClicked

private void t3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t3ActionPerformed

}//GEN-LAST:event_t3ActionPerformed
frame.pack();
frame.setVisible(true);
}

private void btPTNOActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPTNOActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_btPTNOActionPerformed
public javax.swing.JLabel getErrorLabel() {
return errorLabel;
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
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(MyJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MyJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MyJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
} catch (Exception ex) {
java.util.logging.Logger.getLogger(MyJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MyJFrame().setVisible(true);
}
java.awt.EventQueue.invokeLater(() -> {
new MyJFrame().setVisible(true);
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton ShowUTR1;
private javax.swing.JTextField bitByteInput;
private javax.swing.JTextField bitByteOutput;
private javax.swing.JButton btBitByte;
private javax.swing.JButton btLimparTudo;
private javax.swing.JButton btPTNO;
private javax.swing.JLabel errorLabel;
private javax.swing.JButton jButton_show_CColor;
private javax.swing.JDesktopPane jDesktopPane1;
private javax.swing.JLabel jLabel1;
Expand All @@ -363,9 +292,7 @@ public void run() {
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JTextField t1;
private javax.swing.JTextField t2;
private javax.swing.JTextField t3;
private javax.swing.JTextField t4;
private javax.swing.JTextField ptnoInput;
private javax.swing.JTextField ptnoOutput;
// End of variables declaration//GEN-END:variables
}
Loading