/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package swingarea;
/**
*
* @author Logan
*/
public class AreaCalculator extends javax.swing.JFrame {
public AreaCalculator() {
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() {
buttonGroup1 = new javax.swing.ButtonGroup();
dimension1Label = new javax.swing.JLabel();
rectangleRadioButton = new javax.swing.JRadioButton();
triangleRadioButton = new javax.swing.JRadioButton();
dimension2Label = new javax.swing.JLabel();
dimension1Text = new javax.swing.JTextField();
dimension2Text = new javax.swing.JTextField();
inchesLabel1 = new javax.swing.JLabel();
inchesLabel2 = new javax.swing.JLabel();
calcAreaButton = new javax.swing.JButton();
areaLabel = new javax.swing.JLabel();
outputLabel = new javax.swing.JLabel();
circleRadioButton = new javax.swing.JRadioButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
clearMenuItem = new javax.swing.JMenu();
exitMenuItem = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Area Calculator");
dimension1Label.setText("Dimension 1:");
buttonGroup1.add(rectangleRadioButton);
rectangleRadioButton.setText("Rectangle");
buttonGroup1.add(triangleRadioButton);
triangleRadioButton.setText("Triangle");
dimension2Label.setText("Dimension 2:");
inchesLabel1.setText("inches");
inchesLabel2.setText("inches");
calcAreaButton.setText("Calculate Area");
calcAreaButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
calcAreaButtonActionPerformed(evt);
}
});
areaLabel.setText("Area is:");
buttonGroup1.add(circleRadioButton);
circleRadioButton.setText("Circle");
jMenu1.setText("File");
jMenuBar1.add(jMenu1);
clearMenuItem.setText("Clear");
clearMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearMenuItemActionPerformed(evt);
}
});
jMenuBar1.add(clearMenuItem);
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitMenuItemActionPerformed(evt);
}
});
jMenuBar1.add(exitMenuItem);
setJMenuBar(jMenuBar1);
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)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(circleRadioButton)
.addComponent(dimension1Label))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(dimension1Text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(inchesLabel1))
.addGroup(layout.createSequentialGroup()
.addComponent(rectangleRadioButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(triangleRadioButton))))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(areaLabel))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(calcAreaButton)
.addComponent(outputLabel)))
.addGap(48, 48, 48)))
.addGroup(layout.createSequentialGroup()
.addComponent(dimension2Label)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(dimension2Text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(inchesLabel2))))
);
layout.setVerticalGroup(
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.BASELINE)
.addComponent(circleRadioButton)
.addComponent(rectangleRadioButton)
.addComponent(triangleRadioButton))
.addGap(41, 41, 41)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(dimension1Label)
.addComponent(dimension1Text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(inchesLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(dimension2Label)
.addComponent(dimension2Text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(inchesLabel2))
.addGap(31, 31, 31)
.addComponent(calcAreaButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(areaLabel)
.addGap(20, 20, 20)
.addComponent(outputLabel))
);
pack();
}// </editor-fold>
private void calcAreaButtonActionPerformed(java.awt.event.ActionEvent evt) {
double area = 0;
double areaCircle = 0;
if (circleRadioButton.isSelected())
{
String strRadius = dimension1Text.getText();
int radius = Integer.parseInt(strRadius);
area = areaCircle;
}
String strArea = String.valueOf(area);
outputLabel.setText(strArea + " square inches"); // TODO add your handling code here:
}
public static double areaTriangle(double triBase,double triHeight, double triOutput, int shapeNum) {
triOutput = (triBase*triHeight)/2;
if (shapeNum == 1 ){
return triOutput;
}
}
public static double areaCircle (double circOutput,double circRadi, int shapeNum )
{
{
circOutput = (Math.pow (circRadi, 2)*Math.PI);
if(shapeNum == 2 )
{
return circOutput;
}
}
}
public static double areaRectangle(int rectOutput, int lengthRect, int widthRect, int shapeNum) {
rectOutput = lengthRect*widthRect;
if(shapeNum == 3 ) {
return rectOutput;
}
}
private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void clearMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
double area = 0;
//<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(AreaCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(AreaCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(AreaCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(AreaCalculator.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 AreaCalculator().setVisible(true);
}
});
}
double area = 0;
// Variables declaration - do not modify
private javax.swing.JLabel areaLabel;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JButton calcAreaButton;
private javax.swing.JRadioButton circleRadioButton;
private javax.swing.JMenu clearMenuItem;
private javax.swing.JLabel dimension1Label;
private javax.swing.JTextField dimension1Text;
private javax.swing.JLabel dimension2Label;
private javax.swing.JTextField dimension2Text;
private javax.swing.JMenu exitMenuItem;
private javax.swing.JLabel inchesLabel1;
private javax.swing.JLabel inchesLabel2;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JLabel outputLabel;
private javax.swing.JRadioButton rectangleRadioButton;
private javax.swing.JRadioButton triangleRadioButton;
// End of variables declaration
}