XY Grapher
Submitted by SoulPour777 on Friday, March 15, 2013 - 15:38.
Language
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author SoulPour
- */
- import java.lang.Math;
- import java.util.Random;
- import javax.swing.*;
- public class XY_Grapher extends javax.swing.JFrame {
- /**
- * Creates new form XY_Grapher
- */
- public XY_Grapher() {
- 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() {
- jScrollPane1 = new javax.swing.JScrollPane();
- grapher = new javax.swing.JTextArea();
- graphFunc = new javax.swing.JButton();
- jLabel1 = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("XY Grapher by SoulPour777");
- getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
- grapher.setEditable(false);
- grapher.setColumns(20);
- grapher.setRows(5);
- jScrollPane1.setViewportView(grapher);
- getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, 270, 230));
- graphFunc.setText("Start Graph");
- graphFunc.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- graphFuncActionPerformed(evt);
- }
- });
- getContentPane().add(graphFunc, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 250, 270, 65));
- jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Layout_fin.png"))); // NOI18N
- getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 310, 340));
- pack();
- }// </editor-fold>//GEN-END:initComponents
- private void graphFuncActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphFuncActionPerformed
- // TODO add your handling code here:
- int x[] = {0,0,0};
- int y[] = {0,0,0};
- int rand;
- Random r = new Random();
- String xone;
- String xtwo;
- String yone;
- String ytwo;
- xone = JOptionPane.showInputDialog(null,"Please enter the value of X1: ");
- x[1] = Integer.parseInt(xone);
- xtwo = JOptionPane.showInputDialog(null,"Please enter the value of X2: ");
- x[2] = Integer.parseInt(xtwo);
- yone = JOptionPane.showInputDialog(null,"Please enter the value of Y1: ");
- y[1] = Integer.parseInt(yone);
- ytwo = JOptionPane.showInputDialog(null,"Please enter the value of Y2: ");
- y[2] = Integer.parseInt(ytwo);
- int slope = (y[2] - y[1]) / (x[2] - x[1]);
- int yintercept = y[1]- (slope * x[1]);
- rand = (int) (Math.random()*7);
- int upM = slope / -1;
- grapher.setText("Formula: " + "y="+slope+"x + "+yintercept);
- grapher.append("\nSlope: " + slope);
- grapher.append("\nY Intercept: " + yintercept);
- grapher.append("\nParallel Line Formula: " + "y="+slope+"x + "+rand);
- grapher.append("\nPerpendicular Line Formula: " + "y="+upM+"x + "+yintercept);
- }//GEN-LAST:event_graphFuncActionPerformed
- /**
- * @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(XY_Grapher.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(XY_Grapher.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(XY_Grapher.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(XY_Grapher.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 XY_Grapher().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton graphFunc;
- private javax.swing.JTextArea grapher;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JScrollPane jScrollPane1;
- // End of variables declaration//GEN-END:variables
- }
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
- 56 views