XY Grapher

Language
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. /**
  7.  *
  8.  * @author SoulPour
  9.  */
  10. import java.lang.Math;
  11. import java.util.Random;
  12. import javax.swing.*;
  13. public class XY_Grapher extends javax.swing.JFrame {
  14.  
  15.     /**
  16.      * Creates new form XY_Grapher
  17.      */
  18.     public XY_Grapher() {
  19.         initComponents();
  20.     }
  21.  
  22.     /**
  23.      * This method is called from within the constructor to initialize the form.
  24.      * WARNING: Do NOT modify this code. The content of this method is always
  25.      * regenerated by the Form Editor.
  26.      */
  27.     @SuppressWarnings("unchecked")
  28.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  29.     private void initComponents() {
  30.  
  31.         jScrollPane1 = new javax.swing.JScrollPane();
  32.         grapher = new javax.swing.JTextArea();
  33.         graphFunc = new javax.swing.JButton();
  34.         jLabel1 = new javax.swing.JLabel();
  35.  
  36.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  37.         setTitle("XY Grapher by SoulPour777");
  38.         getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
  39.  
  40.         grapher.setEditable(false);
  41.         grapher.setColumns(20);
  42.         grapher.setRows(5);
  43.         jScrollPane1.setViewportView(grapher);
  44.  
  45.         getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, 270, 230));
  46.  
  47.         graphFunc.setText("Start Graph");
  48.         graphFunc.addActionListener(new java.awt.event.ActionListener() {
  49.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  50.                 graphFuncActionPerformed(evt);
  51.             }
  52.         });
  53.         getContentPane().add(graphFunc, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 250, 270, 65));
  54.  
  55.         jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Layout_fin.png"))); // NOI18N
  56.         getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 310, 340));
  57.  
  58.         pack();
  59.     }// </editor-fold>//GEN-END:initComponents
  60.  
  61.     private void graphFuncActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphFuncActionPerformed
  62.         // TODO add your handling code here:
  63.         int x[] = {0,0,0};
  64.                 int y[] = {0,0,0};
  65.                 int rand;
  66.                 Random r = new Random();
  67.                 String xone;
  68.                 String xtwo;
  69.                 String yone;
  70.                 String ytwo;
  71.                 xone = JOptionPane.showInputDialog(null,"Please enter the value of X1: ");
  72.                    x[1] = Integer.parseInt(xone);
  73.                 xtwo = JOptionPane.showInputDialog(null,"Please enter the value of X2: ");
  74.                    x[2] = Integer.parseInt(xtwo);
  75.                 yone = JOptionPane.showInputDialog(null,"Please enter the value of Y1: ");
  76.                    y[1] = Integer.parseInt(yone);
  77.                 ytwo = JOptionPane.showInputDialog(null,"Please enter the value of Y2: ");
  78.                     y[2] = Integer.parseInt(ytwo);
  79.                 int slope = (y[2] - y[1]) / (x[2] - x[1]);
  80.                 int yintercept = y[1]- (slope * x[1]);
  81.                 rand = (int) (Math.random()*7);
  82.                 int upM = slope / -1;
  83.                 grapher.setText("Formula: " + "y="+slope+"x + "+yintercept);
  84.                 grapher.append("\nSlope: " + slope);
  85.                 grapher.append("\nY Intercept: " + yintercept);
  86.                 grapher.append("\nParallel Line Formula: " + "y="+slope+"x + "+rand);
  87.                 grapher.append("\nPerpendicular Line Formula: " + "y="+upM+"x + "+yintercept);
  88.     }//GEN-LAST:event_graphFuncActionPerformed
  89.  
  90.     /**
  91.      * @param args the command line arguments
  92.      */
  93.     public static void main(String args[]) {
  94.         /* Set the Nimbus look and feel */
  95.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  96.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  97.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  98.          */
  99.         try {
  100.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  101.                 if ("Nimbus".equals(info.getName())) {
  102.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  103.                     break;
  104.                 }
  105.             }
  106.         } catch (ClassNotFoundException ex) {
  107.             java.util.logging.Logger.getLogger(XY_Grapher.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  108.         } catch (InstantiationException ex) {
  109.             java.util.logging.Logger.getLogger(XY_Grapher.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  110.         } catch (IllegalAccessException ex) {
  111.             java.util.logging.Logger.getLogger(XY_Grapher.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  112.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  113.             java.util.logging.Logger.getLogger(XY_Grapher.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  114.         }
  115.         //</editor-fold>
  116.  
  117.         /* Create and display the form */
  118.         java.awt.EventQueue.invokeLater(new Runnable() {
  119.             public void run() {
  120.                 new XY_Grapher().setVisible(true);
  121.             }
  122.         });
  123.     }
  124.     // Variables declaration - do not modify//GEN-BEGIN:variables
  125.     private javax.swing.JButton graphFunc;
  126.     private javax.swing.JTextArea grapher;
  127.     private javax.swing.JLabel jLabel1;
  128.     private javax.swing.JScrollPane jScrollPane1;
  129.     // End of variables declaration//GEN-END:variables
  130. }

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment