Aplikasi sederhana mencari Massa Jenis,Massa dan Volum


import javax.swing.ButtonGroup;

import javax.swing.JOptionPane;

/*
 * MassaJenis.java
 *
 * Created on Dec 6, 2011, 11:04:17 AM
 */
/**
 *
 * @author Sony
 */
public class MassaJenis extends javax.swing.JFrame {

/** Creates new form MassaJenis */
 public MassaJenis() {
 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() {

jPanel1 = new javax.swing.JPanel();
 massaJenis = new javax.swing.JTextField();
 jLabel1 = new javax.swing.JLabel();
 jLabel2 = new javax.swing.JLabel();
 jLabel3 = new javax.swing.JLabel();
 massa = new javax.swing.JTextField();
 volum = new javax.swing.JTextField();
 proses = new javax.swing.JButton();
 jLabel4 = new javax.swing.JLabel();
 jLabel5 = new javax.swing.JLabel();
 jLabel6 = new javax.swing.JLabel();
 exit = new javax.swing.JButton();
 exit1 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 setTitle("MASSA JENIS");

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Input Nilai"));
 jPanel1.setName("jPanel1"); // NOI18N

massaJenis.setName("massaJenis"); // NOI18N

jLabel1.setText("Massa Jenis");
 jLabel1.setName("jLabel1"); // NOI18N

jLabel2.setText("Massa");
 jLabel2.setName("jLabel2"); // NOI18N

jLabel3.setText("Volum");
 jLabel3.setName("jLabel3"); // NOI18N

massa.setName("massa"); // NOI18N

volum.setName("volum"); // NOI18N

proses.setText("Proses");
 proses.setName("proses"); // NOI18N
 proses.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 prosesActionPerformed(evt);
 }
 });

jLabel4.setText("Kg/m3 ");
 jLabel4.setName("jLabel4"); // NOI18N

jLabel5.setText("Kg");
 jLabel5.setName("jLabel5"); // NOI18N

jLabel6.setText("m3");
 jLabel6.setName("jLabel6"); // NOI18N

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
 jPanel1.setLayout(jPanel1Layout);
 jPanel1Layout.setHorizontalGroup(
 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addContainerGap()
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(jLabel1)
 .addComponent(jLabel2)
 .addComponent(jLabel3))
 .addGap(18, 18, 18)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
 .addComponent(massaJenis)
 .addComponent(massa)
 .addComponent(volum, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(jLabel4)
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addComponent(jLabel5)
 .addGap(30, 30, 30)
 .addComponent(proses))
 .addComponent(jLabel6))
 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 );
 jPanel1Layout.setVerticalGroup(
 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addContainerGap()
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(massaJenis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jLabel1)
 .addComponent(jLabel4))
 .addGap(5, 5, 5)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(jLabel2)
 .addComponent(massa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(proses)
 .addComponent(jLabel5))
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(jLabel3)
 .addComponent(volum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jLabel6))
 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 );

exit.setText("X");
 exit.setName("exit"); // NOI18N
 exit.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 exitActionPerformed(evt);
 }
 });

exit1.setText("Bersih");
 exit1.setName("exit1"); // NOI18N
 exit1.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 exit1ActionPerformed(evt);
 }
 });

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
 getContentPane().setLayout(layout);
 layout.setHorizontalGroup(
 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(layout.createSequentialGroup()
 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(layout.createSequentialGroup()
 .addContainerGap()
 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addGap(18, 18, 18)
 .addComponent(exit))
 .addGroup(layout.createSequentialGroup()
 .addGap(294, 294, 294)
 .addComponent(exit1)))
 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 );
 layout.setVerticalGroup(
 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
 .addContainerGap()
 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
 .addGroup(layout.createSequentialGroup()
 .addComponent(exit1)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(exit))
 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 .addContainerGap())
 );

pack();
 }// </editor-fold>

private void prosesActionPerformed(java.awt.event.ActionEvent evt) {

//double mj = Double.parseDouble(massaJenis.getText());
 //double m = Double.parseDouble(massa.getText());
 //double v = Double.parseDouble(volum.getText());

 if ( "".equals(massaJenis.getText())){
 //double mj = Double.parseDouble(massaJenis.getText());
 double m = Double.parseDouble(massa.getText());
 double v = Double.parseDouble(volum.getText());
 double mj = m/v;
 massaJenis.setText(String.valueOf(mj));
 } else if ("".equals(massa.getText())) {
 double mj = Double.parseDouble(massaJenis.getText());
 //double m = Double.parseDouble(massa.getText());
 double v = Double.parseDouble(volum.getText());
 double m = mj*v;
 massa.setText(String.valueOf(m));
 } else {
 double mj = Double.parseDouble(massaJenis.getText());
 double m = Double.parseDouble(massa.getText());
 //double v = Double.parseDouble(volum.getText());
 double v = mj*m;
 volum.setText(String.valueOf(v));
 }

 // TODO add your handling code here:
}

private void exitActionPerformed(java.awt.event.ActionEvent evt) {
int ps = 0;
 ps =JOptionPane.showConfirmDialog(null,"Keluar dari form");
 if(ps == JOptionPane.OK_OPTION){
 // System.exit(1);
 // new Menu().isVisible(true);
 dispose();
 }

 else{

 }

 // TODO add your handling code here:
}

private void exit1ActionPerformed(java.awt.event.ActionEvent evt) {
massa.setText(null);
massaJenis.setText(null);
volum.setText(null);
// TODO add your handling code here:
}

/**
 * @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(MassaJenis.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
 } catch (InstantiationException ex) {
 java.util.logging.Logger.getLogger(MassaJenis.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
 } catch (IllegalAccessException ex) {
 java.util.logging.Logger.getLogger(MassaJenis.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
 java.util.logging.Logger.getLogger(MassaJenis.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 MassaJenis().setVisible(true);
 }
 });
 }
 // Variables declaration - do not modify
 private javax.swing.JButton exit;
 private javax.swing.JButton exit1;
 private javax.swing.JLabel jLabel1;
 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.JPanel jPanel1;
 private javax.swing.JTextField massa;
 private javax.swing.JTextField massaJenis;
 private javax.swing.JButton proses;
 private javax.swing.JTextField volum;
 // End of variables declaration
}
 "Form Mencari Massa jenis, Massa dan Volum"
About these ads
By hrynaldi Posted in Java

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s