Java tutorial
/* * 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. */ package numerical; import com.itextpdf.text.BaseColor; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Font; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfWriter; import java.awt.HeadlessException; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import javax.swing.JFileChooser; import javax.swing.JOptionPane; /** * * @author Cyril */ public class Determinants extends javax.swing.JFrame { /** * Creates new form Determinants */ public Determinants() { 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") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel9 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); btn_solve = new javax.swing.JButton(); txt_a1 = new javax.swing.JTextField(); jLabel13 = new javax.swing.JLabel(); txt_c3 = new javax.swing.JTextField(); jLabel14 = new javax.swing.JLabel(); txt_c1 = new javax.swing.JTextField(); btn_clear = new javax.swing.JButton(); txt_b2 = new javax.swing.JTextField(); txt_b3 = new javax.swing.JTextField(); txt_a3 = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); txt_a2 = new javax.swing.JTextField(); btn_save = new javax.swing.JButton(); txt_b1 = new javax.swing.JTextField(); txt_r3 = new javax.swing.JTextField(); txt_r1 = new javax.swing.JTextField(); txt_c2 = new javax.swing.JTextField(); txt_r2 = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); txt_result = new javax.swing.JTextArea(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Determinants"); setResizable(false); jLabel9.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel9.setText("Determinants"); jLabel12.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel12.setText("="); btn_solve.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N btn_solve.setText("Solve"); btn_solve.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btn_solveActionPerformed(evt); } }); txt_a1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N txt_a1.setHorizontalAlignment(javax.swing.JTextField.CENTER); jLabel13.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel13.setText("c"); txt_c3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N txt_c3.setHorizontalAlignment(javax.swing.JTextField.CENTER); jLabel14.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel14.setText("c"); txt_c1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N txt_c1.setHorizontalAlignment(javax.swing.JTextField.CENTER); btn_clear.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N btn_clear.setText("Clear"); btn_clear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btn_clearActionPerformed(evt); } }); txt_b2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N txt_b2.setHorizontalAlignment(javax.swing.JTextField.CENTER); txt_b3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N txt_b3.setHorizontalAlignment(javax.swing.JTextField.CENTER); txt_a3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N txt_a3.setHorizontalAlignment(javax.swing.JTextField.CENTER); jLabel6.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel6.setText("Result:"); txt_a2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N txt_a2.setHorizontalAlignment(javax.swing.JTextField.CENTER); btn_save.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N btn_save.setText("Save as PDF"); btn_save.setEnabled(false); btn_save.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btn_saveActionPerformed(evt); } }); txt_b1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N txt_b1.setHorizontalAlignment(javax.swing.JTextField.CENTER); txt_r3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N txt_r3.setHorizontalAlignment(javax.swing.JTextField.CENTER); txt_r1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N txt_r1.setHorizontalAlignment(javax.swing.JTextField.CENTER); txt_c2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N txt_c2.setHorizontalAlignment(javax.swing.JTextField.CENTER); txt_r2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N txt_r2.setHorizontalAlignment(javax.swing.JTextField.CENTER); jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel2.setText("b"); jLabel3.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel3.setText("c"); jLabel4.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel4.setText("a"); jLabel5.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel5.setText("b"); jLabel7.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel7.setText("a"); jLabel8.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel8.setText("b"); jLabel10.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel10.setText("="); jLabel11.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel11.setText("="); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText("a"); txt_result.setEditable(false); txt_result.setColumns(20); txt_result.setRows(5); jScrollPane1.setViewportView(txt_result); 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) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel9) .addGroup(layout.createSequentialGroup() .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(txt_a1).addComponent(txt_a2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(txt_a3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel7).addComponent(jLabel4).addComponent(jLabel1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(txt_b2).addComponent(txt_b1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(txt_b3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(2, 2, 2) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup().addComponent(jLabel5) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(txt_c2)) .addGroup(layout.createSequentialGroup().addComponent(jLabel8) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(txt_c3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addComponent(jLabel2) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(txt_c1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel12)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel11).addComponent(jLabel10)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txt_r3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(txt_r1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txt_r2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(18, 18, 18) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(btn_save, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btn_clear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btn_solve, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(jLabel6)).addGap(0, 18, Short.MAX_VALUE)) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel9) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jLabel4).addComponent(txt_a1).addComponent(txt_b1) .addComponent(jLabel2).addComponent(txt_c1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3).addComponent(jLabel10))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btn_solve).addComponent(txt_r1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(txt_a2, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(txt_a3, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel7))) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txt_b2, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(txt_c2, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel13) .addComponent(jLabel11))) .addGap(11, 11, 11)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btn_clear, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( txt_r2, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))) .addGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(txt_c3, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btn_save, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txt_r3, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel14) .addComponent(jLabel12)))))) .addComponent(txt_b3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addComponent(jLabel5).addGap(17, 17, 17) .addComponent(jLabel8))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jLabel6) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); pack(); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private void btn_solveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_solveActionPerformed int a1 = Integer.parseInt(txt_a1.getText()); int b1 = Integer.parseInt(txt_b1.getText()); int c1 = Integer.parseInt(txt_c1.getText()); int a2 = Integer.parseInt(txt_a2.getText()); int b2 = Integer.parseInt(txt_b2.getText()); int c2 = Integer.parseInt(txt_c2.getText()); int a3 = Integer.parseInt(txt_a3.getText()); int b3 = Integer.parseInt(txt_b3.getText()); int c3 = Integer.parseInt(txt_c3.getText()); int r1 = Integer.parseInt(txt_r1.getText()); int r2 = Integer.parseInt(txt_r2.getText()); int r3 = Integer.parseInt(txt_r3.getText()); int m1 = -1; int m2 = 1; int m3 = -1; txt_result.setText(""); txt_result.append("Equation: \n"); if (b1 > 0 && c1 > 0) txt_result.append(a1 + "a +" + b1 + "b +" + c1 + "c = " + r1 + "\n"); if (b1 < 0 && c1 > 0) txt_result.append(a1 + "a " + b1 + "b +" + c1 + "c = " + r1 + "\n"); if (b1 > 0 && c1 < 0) txt_result.append(a1 + "a +" + b1 + "b " + c1 + "c = " + r1 + "\n"); if (b1 < 0 && c1 < 0) txt_result.append(a1 + "a " + b1 + "b " + c1 + "c = " + r1 + "\n"); if (b2 > 0 && c2 > 0) txt_result.append(a2 + "a +" + b2 + "b +" + c2 + "c = " + r2 + "\n"); if (b2 < 0 && c2 > 0) txt_result.append(a2 + "a " + b2 + "b +" + c2 + "c = " + r2 + "\n"); if (b2 > 0 && c2 < 0) txt_result.append(a2 + "a +" + b2 + "b " + c2 + "c = " + r2 + "\n"); if (b2 < 0 && c2 < 0) txt_result.append(a2 + "a " + b2 + "b " + c2 + "c = " + r2 + "\n"); if (b3 > 0 && c3 > 0) txt_result.append(a3 + "a +" + b3 + "b +" + c3 + "c = " + r3 + "\n\n"); if (b3 < 0 && c3 > 0) txt_result.append(a3 + "a " + b3 + "b +" + c3 + "c = " + r3 + "\n\n"); if (b3 > 0 && c3 < 0) txt_result.append(a3 + "a +" + b3 + "b " + c3 + "c = " + r3 + "\n\n"); if (b3 < 0 && c3 < 0) txt_result.append(a3 + "a " + b3 + "b " + c3 + "c = " + r3 + "\n\n"); // computation for D int dr = ((a1 * b2 * c3) + (b1 * c2 * a3) + (c1 * a2 * b3)) - ((a3 * b2 * c1) + (b3 * c2 * a1) + (c3 * a2 * b1)); txt_result.append("Computation for D\n"); txt_result.append(a1 + " " + b1 + " " + c1 + " : " + a1 + " " + b1 + "\n"); txt_result.append(a2 + " " + b2 + " " + c2 + " : " + a2 + " " + b2 + "\n"); txt_result.append(a3 + " " + b3 + " " + c3 + " : " + a3 + " " + b3 + "\n\n"); txt_result.append("[" + " (" + a1 + ")" + " (" + b2 + ")" + " (" + c3 + ")" + " +" + " (" + b1 + ")" + " (" + c2 + ")" + " (" + a3 + ") + " + " (" + c1 + ")" + " (" + a2 + ")" + " (" + b3 + ") ] - [" + " (" + a3 + ")" + " (" + b2 + ")" + " (" + c1 + ") + " + " (" + b3 + ")" + " (" + c2 + ")" + " (" + a1 + ") + " + " (" + c3 + ")" + " (" + a2 + ")" + " (" + b1 + ") ]" + "\n"); txt_result.append( "[ (" + (a1 * b2 * c3) + ") + (" + (b1 * c2 * a3) + ") + (" + (c1 * a2 * b3) + ")]" + " - " + "[ (" + (a3 * b2 * c1) + ") + (" + (b3 * c2 * a1) + ") + (" + (c3 * a2 * b1) + ") ]" + "\n"); txt_result.append("(" + ((a1 * b2 * c3) + (b1 * c2 * a3) + (c1 * a2 * b3)) + ")" + " - " + "(" + ((a3 * b2 * c1) + (b3 * c2 * a1) + (c3 * a2 * b1)) + ")" + "\n"); txt_result.append("D = " + dr + "\n\n"); // computation for A int ar = ((r1 * b2 * c3) + (b1 * c2 * r3) + (c1 * r2 * b3)) - ((r3 * b2 * c1) + (b3 * c2 * r1) + (c3 * r2 * b1)); txt_result.append("Computation for A\n"); txt_result.append(r1 + " " + b1 + " " + c1 + " : " + r1 + " " + b1 + "\n"); txt_result.append(r2 + " " + b2 + " " + c2 + " : " + r2 + " " + b2 + "\n"); txt_result.append(r3 + " " + b3 + " " + c3 + " : " + r3 + " " + b3 + "\n\n"); txt_result.append("[" + " (" + r1 + ")" + " (" + b2 + ")" + " (" + c3 + ")" + " +" + " (" + b1 + ")" + " (" + c2 + ")" + " (" + r3 + ") +" + " (" + c1 + ")" + " (" + r2 + ")" + " (" + b3 + ") ] - [" + " (" + r3 + ")" + " (" + b2 + ")" + " (" + c1 + ") +" + " (" + b3 + ")" + " (" + c2 + ")" + " (" + r1 + ") +" + " (" + c3 + ")" + " (" + r2 + ")" + " (" + b1 + ")]" + "\n"); txt_result.append( "[ (" + (r1 * b2 * c3) + ") + (" + (b1 * c2 * r3) + ") + (" + (c1 * r2 * b3) + ")]" + " - " + "[ (" + (r3 * b2 * c1) + ") + (" + (b3 * c2 * r1) + ") + (" + (c3 * r2 * b1) + ") ]" + "\n"); txt_result.append("(" + ((r1 * b2 * c3) + (b1 * c2 * r3) + (c1 * r2 * b3)) + ")" + " - " + "(" + ((r3 * b2 * c1) + (b3 * c2 * r1) + (c3 * r2 * b1)) + ")" + "\n"); txt_result.append(ar + "/" + dr + "\n"); txt_result.append("A = " + (ar / dr) + "\n\n"); // computation for B int br = ((a1 * r2 * c3) + (r1 * c2 * a3) + (c1 * a2 * r3)) - ((a3 * r2 * c1) + (r3 * c2 * a1) + (c3 * a2 * r1)); txt_result.append("Computation for B\n"); txt_result.append(a1 + " " + r1 + " " + c1 + " : " + a1 + " " + r1 + "\n"); txt_result.append(a2 + " " + r2 + " " + c2 + " : " + a2 + " " + r2 + "\n"); txt_result.append(a3 + " " + r3 + " " + c3 + " : " + a3 + " " + r3 + "\n\n"); txt_result.append("[" + " (" + a1 + ")" + " (" + r2 + ")" + " (" + c3 + ")" + " +" + " (" + r1 + ")" + " (" + c2 + ")" + " (" + a3 + ") +" + " (" + c1 + ")" + " (" + a2 + ")" + " (" + r3 + ") ] - [" + " (" + a3 + ")" + " (" + r2 + ")" + " (" + c1 + ") +" + " (" + r3 + ")" + " (" + c2 + ")" + " (" + a1 + ") +" + " (" + c3 + ")" + " (" + a2 + ")" + " (" + r1 + ")]" + "\n"); txt_result.append( "[ (" + (a1 * r2 * c3) + ") + (" + (r1 * c2 * a3) + ") + (" + (c1 * a2 * r3) + ")]" + " - " + "[ (" + (a3 * r2 * c1) + ") + (" + (r3 * c2 * a1) + ") + (" + (c3 * a2 * r1) + ") ]" + "\n"); txt_result.append("(" + ((a1 * r2 * c3) + (r1 * c2 * a3) + (c1 * a2 * r3)) + ")" + " - " + "(" + ((a3 * r2 * c1) + (r3 * c2 * a1) + (c3 * a2 * r1)) + ")" + "\n"); txt_result.append(br + "/" + dr + "\n"); txt_result.append("B = " + (br / dr) + "\n\n"); // computation for C int cr = ((a3 * b2 * r1) + (b3 * r2 * a1) + (r3 * a2 * b1)) - ((a1 * b2 * r3) + (b1 * r2 * a3) + (r1 * a2 * b3)); txt_result.append("Computation for C\n"); txt_result.append(a1 + " " + b1 + " " + r1 + " : " + a1 + " " + b1 + "\n"); txt_result.append(a2 + " " + b2 + " " + r2 + " : " + a2 + " " + b2 + "\n"); txt_result.append(a3 + " " + b3 + " " + r3 + " : " + a3 + " " + b3 + "\n\n"); txt_result.append("[" + " (" + a1 + ")" + " (" + b2 + ")" + " (" + r3 + ")" + " +" + " (" + b1 + ")" + " (" + r2 + ")" + " (" + a3 + ") +" + " (" + r1 + ")" + " (" + a2 + ")" + " (" + b3 + ") ] - [" + " (" + a3 + ")" + " (" + b2 + ")" + " (" + r1 + ") +" + " (" + b3 + ")" + " (" + r2 + ")" + " (" + a1 + ") +" + " (" + r3 + ")" + " (" + a2 + ")" + " (" + b1 + ")]" + "\n"); txt_result.append( "[ (" + +(a3 * b2 * r1) + ") + (" + (b3 * r2 * a1) + ") + (" + (r3 * a2 * b1) + ")" + " - " + "(" + (a1 * b2 * r3) + ") + (" + (b1 * r2 * a3) + ") + (" + (r1 * a2 * b3) + ") ]" + "\n"); txt_result.append("(" + ((a3 * b2 * r1) + (b3 * r2 * a1) + (r3 * a2 * b1)) + ")" + " - " + "(" + ((a1 * b2 * r3) + (b1 * r2 * a3) + (r1 * a2 * b3)) + ")" + "\n"); txt_result.append(cr + "/" + dr + "\n"); txt_result.append("C = " + (cr / dr) + "\n\n"); btn_save.setEnabled(true); }//GEN-LAST:event_btn_solveActionPerformed private void btn_clearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_clearActionPerformed btn_save.setEnabled(false); txt_a1.setText(""); txt_b1.setText(""); txt_c1.setText(""); txt_a2.setText(""); txt_b2.setText(""); txt_c2.setText(""); txt_a3.setText(""); txt_b3.setText(""); txt_c3.setText(""); txt_r1.setText(""); txt_r2.setText(""); txt_r3.setText(""); txt_result.setText(""); }//GEN-LAST:event_btn_clearActionPerformed private void btn_saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_saveActionPerformed JFileChooser jfc = new JFileChooser(); jfc.setCurrentDirectory(new File("/My Documents")); int return_val = jfc.showSaveDialog(rootPane); if (return_val == JFileChooser.APPROVE_OPTION) { Document doc = new Document(); try { jfc.getSelectedFile(); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(jfc.getSelectedFile() + ".pdf")); doc.open(); Font f = new Font(Font.FontFamily.TIMES_ROMAN, 12.0f, Font.NORMAL, BaseColor.BLACK); Font f1 = new Font(Font.FontFamily.TIMES_ROMAN, 18.0f, Font.BOLD, BaseColor.BLACK); Paragraph paragraph = new Paragraph(null, f); Paragraph title = new Paragraph(null, f1); title.add("Determinants \n"); paragraph.add(txt_result.getText()); doc.add(title); doc.add(paragraph); doc.close(); writer.close(); JOptionPane.showMessageDialog(rootPane, "Successfully saved!"); } catch (FileNotFoundException | DocumentException | HeadlessException e) { System.err.println(e); } } }//GEN-LAST:event_btn_saveActionPerformed /** * @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(Determinants.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Determinants.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Determinants.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Determinants.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Determinants().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btn_clear; private javax.swing.JButton btn_save; private javax.swing.JButton btn_solve; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; 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.JLabel jLabel9; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField txt_a1; private javax.swing.JTextField txt_a2; private javax.swing.JTextField txt_a3; private javax.swing.JTextField txt_b1; private javax.swing.JTextField txt_b2; private javax.swing.JTextField txt_b3; private javax.swing.JTextField txt_c1; private javax.swing.JTextField txt_c2; private javax.swing.JTextField txt_c3; private javax.swing.JTextField txt_r1; private javax.swing.JTextField txt_r2; private javax.swing.JTextField txt_r3; private javax.swing.JTextArea txt_result; // End of variables declaration//GEN-END:variables }