/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* CelsiusConverterGUI.java
*
* Created on Mar 5, 2011, 12:59:24 AM
*/
/**
*
* @author Andrew
*/
public class CelsiusConverterGUI extends javax.swing.JFrame {
/** Creates new form CelsiusConverterGUI */
public CelsiusConverterGUI() {
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">
private void initComponents() {
X1label = new javax.swing.JLabel();
Y1label = new javax.swing.JLabel();
X2label = new javax.swing.JLabel();
Y2label = new javax.swing.JLabel();
X1field = new javax.swing.JTextField();
Y1field = new javax.swing.JTextField();
X2field = new javax.swing.JTextField();
Y2field = new javax.swing.JTextField();
MathButton = new javax.swing.JButton();
answerlabel = new javax.swing.JLabel();
answerlabel1 = new javax.swing.JLabel();
endlabel = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Math Y2-Y1/ X2-X1");
X1label.setFont(new java.awt.Font("Tahoma", 0, 12));
X1label.setText("X1");
Y1label.setText("Y1");
X2label.setText("X2");
Y2label.setText("Y2");
MathButton.setText("Do Math");
MathButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
MathButtonActionPerformed(evt);
}
});
answerlabel.setText("Answer");
answerlabel1.setText("y-intercept Answer");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(X2label)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(X2field, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(X1label)
.addGap(2, 2, 2)
.addComponent(X1field, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
.addGroup(layout.createSequentialGroup()
.addComponent(MathButton)
.addGap(66, 66, 66)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(endlabel)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(answerlabel1)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(answerlabel)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(Y1label)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Y1field, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(Y2label)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Y2field, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE))))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(X1label)
.addComponent(Y1label)
.addComponent(Y1field, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(X1field, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(7, 7, 7)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(X2label)
.addComponent(X2field, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Y2label)
.addComponent(Y2field, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(MathButton)
.addComponent(answerlabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(answerlabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(endlabel)
.addContainerGap(46, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void MathButtonActionPerformed(java.awt.event.ActionEvent evt) {
int X1 = (int)(Double.parseDouble(X1field.getText()));
int X2 = (int)(Double.parseDouble(X2field.getText()));
int Y1 = (int)(Double.parseDouble(Y1field.getText()));
int Y2 = (int)(Double.parseDouble(Y2field.getText()));
int answer = Y2 - Y1;
int answer1 = X2 - X1;
int answer3 = answer / answer1;
answerlabel.setText("m = "+ answer + "/" + answer1);
int b;
int answer2 = b = Y1 - (answer3 * X1);
answerlabel1.setText("b = " + answer2);
endlabel.setText("Y="+ answer3 +"X+"+ answer2);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CelsiusConverterGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton MathButton;
private javax.swing.JTextField X1field;
private javax.swing.JLabel X1label;
private javax.swing.JTextField X2field;
private javax.swing.JLabel X2label;
private javax.swing.JTextField Y1field;
private javax.swing.JLabel Y1label;
private javax.swing.JTextField Y2field;
private javax.swing.JLabel Y2label;
private javax.swing.JLabel answerlabel;
private javax.swing.JLabel answerlabel1;
private javax.swing.JLabel endlabel;
// End of variables declaration
}