import java.text.DecimalFormat; import java.util.InputMismatchException; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author ANDRE */ public class C1 extends javax.swing.JFrame { /** * Creates new form C1 */ public C1() { initComponents(); } /** * 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. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); resistor1 = new javax.swing.JTextField(); potenciaresistor1 = new javax.swing.JTextField(); resistor2 = new javax.swing.JTextField(); potenciaresistor2 = new javax.swing.JTextField(); modulofonte = new javax.swing.JTextField(); modofonte = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); result = new javax.swing.JTextArea(); btOk = new javax.swing.JButton(); btLimpar = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Circuito 1 - Resistores em série"); jLabel1.setText("Valor R1 (Ohms):"); jLabel2.setText("Potência R1 (Watts) :"); jLabel3.setText("Valor R2 (Ohms):"); jLabel4.setText("Potência R2 (Ohms):"); jLabel5.setText("Módulo da Fonte (módulo da fonte):"); jLabel6.setText("Modo da Fonte (V ou A):"); resistor1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { resistor1ActionPerformed(evt); } }); potenciaresistor1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { potenciaresistor1ActionPerformed(evt); } }); resistor2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { resistor2ActionPerformed(evt); } }); potenciaresistor2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { potenciaresistor2ActionPerformed(evt); } }); modulofonte.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { modulofonteActionPerformed(evt); } }); modofonte.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { modofonteActionPerformed(evt); } }); jLabel7.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N jLabel7.setText("Clique em OK os resultados desse circuito."); jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/circuito-serie-de-resistores.png"))); // NOI18N result.setColumns(20); result.setRows(5); jScrollPane1.setViewportView(result); btOk.setText("OK"); btOk.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btOkActionPerformed(evt); } }); btLimpar.setText("Limpar"); btLimpar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btLimparActionPerformed(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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 654, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5) .addComponent(jLabel4) .addComponent(jLabel3) .addComponent(jLabel2) .addComponent(jLabel1)) .addGap(22, 22, 22) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(modulofonte, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(potenciaresistor2, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(potenciaresistor1, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(resistor1, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(resistor2, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup() .addComponent(jLabel6) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(modofonte, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(jLabel7)) .addGap(46, 46, 46)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(btLimpar) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btOk) .addGap(76, 76, 76))) .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 344, javax.swing.GroupLayout.PREFERRED_SIZE)))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(resistor1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(potenciaresistor1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(resistor2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(potenciaresistor2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(modulofonte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6) .addComponent(modofonte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel7) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btOk) .addComponent(btLimpar))) .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE) .addContainerGap()) ); pack(); setLocationRelativeTo(null); }// //GEN-END:initComponents private void resistor1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resistor1ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_resistor1ActionPerformed private void potenciaresistor1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_potenciaresistor1ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_potenciaresistor1ActionPerformed private void potenciaresistor2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_potenciaresistor2ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_potenciaresistor2ActionPerformed private void modulofonteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modulofonteActionPerformed // TODO add your handling code here: }//GEN-LAST:event_modulofonteActionPerformed private void btOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOkActionPerformed if(resistor1.getText().isEmpty()||potenciaresistor1.getText().isEmpty() ||resistor2.getText().isEmpty()||potenciaresistor1.getText().isEmpty() ||modulofonte.getText().isEmpty()||modofonte.getText().isEmpty()|| (Double.parseDouble(resistor1.getText())<= 0.0)||(Double.parseDouble(potenciaresistor1.getText())<= 0.0) ||(Double.parseDouble(resistor2.getText())<= 0.0)||(Double.parseDouble(potenciaresistor2.getText())<= 0.0) ||(Double.parseDouble(modulofonte.getText()) <= 0.0)){ result.append("Há campo(s) vazio(s) ou campos de texto com valores negativos ou maior que 0.\n"); } else{ result.append("Atenção a entrada de dados!!!!\n"); Circuito1 c1 = new Circuito1(); DecimalFormat f = new DecimalFormat("####0.0000"); c1.parametros(new Resistor(Double.parseDouble(potenciaresistor1.getText()),Double.parseDouble(resistor1.getText())),new Resistor(Double.parseDouble(potenciaresistor2.getText()),Double.parseDouble(resistor2.getText())), new Fonte(0.0,Double.parseDouble(modulofonte.getText()))); if("V".equals(modofonte.getText())){ result.append("\nResistência Equivalente: " + f.format(c1.equivalente()) + " Ohms\nCorrente Elétrica: " + f.format(c1.corrente()) + " A\nTensão R1:" + f.format(c1.tensao1()) + " V\nTensão R2:" + f.format(c1.tensao2()) + " V\nPotência R1:" + f.format(c1.potencia1()) + " Watts\nPotência R2:" + f.format(c1.potencia2()) + "Watts"); } else if("A".equals(modofonte.getText())){ result.append("\nResistência Equivalente: " + f.format(c1.equivalente()) + " Ohms\nCorrente Elétrica: " + f.format(c1.getF().get(0).getValor()) + " A\nTensão R1:" + f.format(c1.tensaor1()) + " V\nTensão R2:" + f.format(c1.tensaor2()) + " V\nPotência R1:" + f.format(c1.potenciar1()) + " Watts\nPotência R2:" + f.format(c1.potenciar2()) + "Watts"); } } }//GEN-LAST:event_btOkActionPerformed private void resistor2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resistor2ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_resistor2ActionPerformed private void modofonteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modofonteActionPerformed // TODO add your handling code here: }//GEN-LAST:event_modofonteActionPerformed private void btLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLimparActionPerformed result.setText(""); }//GEN-LAST:event_btLimparActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ // /* 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(C1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(C1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(C1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(C1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } // /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new C1().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btLimpar; private javax.swing.JButton btOk; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField modofonte; private javax.swing.JTextField modulofonte; private javax.swing.JTextField potenciaresistor1; private javax.swing.JTextField potenciaresistor2; private javax.swing.JTextField resistor1; private javax.swing.JTextField resistor2; private javax.swing.JTextArea result; // End of variables declaration//GEN-END:variables }