Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package luas;
- public class Luas extends javax.swing.JFrame{
- public Luas() {
- initComponents();
- }
- @SuppressWarnings("unchecked")
- private void initComponents(){
- jPanel1 = new javax.swing.JPanel();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jLabel4 = new javax.swing.JLabel();
- alas = new javax.swing.JTextField();
- tinggi = new javax.swing.JTextField();
- hasilsegitiga = new javax.swing.JTextField();
- panjang = new javax.swing.JTextField();
- lebar = new javax.swing.JTextField();
- jarijari = new javax.swing.JTextField();
- hasillingkaran = new javax.swing.JTextField();
- hasilpersegipanjang = new javax.swing.JTextField();
- jLabel23 = new javax.swing.JLabel();
- jLabel24 = new javax.swing.JLabel();
- segitiga = new javax.swing.JButton();
- pesegi = new javax.swing.JButton();
- lingkaran = new javax.swing.JButton();
- jLabel25 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jLabel6 = new javax.swing.JLabel();
- jLabel7 = new javax.swing.JLabel();
- jLabel8 = new javax.swing.JLabel();
- jLabel9 = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
- jLabel1.setText("Luas Segitiga = ");
- jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
- jLabel2.setText("Menghitung Luas Bangun");
- jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
- jLabel3.setText("Luas Persegi Panjang = ");
- jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
- jLabel4.setText("Luas Lingkaran = ");
- alas.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- alasActionPerformed(evt);
- }
- });
- tinggi.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- tinggiActionPerformed(evt);
- }
- });
- hasilsegitiga.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- hasilsegitigaActionPerformed(evt);
- }
- });
- panjang.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- panjangActionPerformed(evt);
- }
- });
- lebar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- lebarActionPerformed(evt);
- }
- });
- jarijari.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jarijariActionPerformed(evt);
- }
- });
- hasillingkaran.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- hasillingkaranActionPerformed(evt);
- }
- });
- hasilpersegipanjang.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- hasilpersegipanjangActionPerformed(evt);
- }
- });
- jLabel23.setText("cm");
- jLabel24.setText("cm");
- segitiga.setText("Hitung");
- segitiga.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- segitigaActionPerformed(evt);
- }
- });
- pesegi.setText("Hitung");
- pesegi.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- pesegiActionPerformed(evt);
- }
- });
- lingkaran.setText("Hitung");
- lingkaran.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- lingkaranActionPerformed(evt);
- }
- });
- jLabel25.setText("cm");
- jLabel5.setText("Alas");
- jLabel6.setText("Tinggi");
- jLabel7.setText("Panjang");
- jLabel8.setText("Lebar");
- jLabel9.setText("Jari – jari");
- 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)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel4)
- .addGap(32, 32, 32))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(alas, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
- .addComponent(panjang, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
- .addComponent(tinggi, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
- .addComponent(hasilsegitiga, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(hasillingkaran, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
- .addComponent(jarijari, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(lebar, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(hasilpersegipanjang, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addGap(4, 4, 4)
- .addComponent(jLabel25, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(pesegi)
- .addComponent(segitiga)))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jLabel24, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
- .addComponent(lingkaran)))
- .addContainerGap())
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jLabel23, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap())))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(63, 63, 63))))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addGap(22, 22, 22)
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel4)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(57, 57, 57)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(hasilsegitiga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel25)
- .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(segitiga))
- .addGap(21, 21, 21)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(panjang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(alas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(tinggi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(lebar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(hasilpersegipanjang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel3)))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(pesegi)
- .addComponent(jLabel23)))
- .addGap(24, 24, 24)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jarijari, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(hasillingkaran, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel24)
- .addComponent(lingkaran))))
- .addGap(48, 48, 48))
- );
- 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()
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addContainerGap())
- );
- pack();
- }// </editor-fold>
- private void alasActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void tinggiActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void hasilsegitigaActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void panjangActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void lebarActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jarijariActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void hasillingkaranActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void hasilpersegipanjangActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void segitigaActionPerformed(java.awt.event.ActionEvent evt) {
- double Alas = Double.parseDouble(alas.getText());
- double Tinggi = Double.parseDouble(tinggi.getText());
- double Hasil = (Alas*Tinggi)/2;
- hasilsegitiga.setText(String.valueOf(Hasil));
- }
- private void pesegiActionPerformed(java.awt.event.ActionEvent evt) {
- double Panjang = Double.parseDouble(panjang.getText());
- double Lebar = Double.parseDouble(lebar.getText());
- double Hasil = (Panjang*Lebar);
- hasilpersegipanjang.setText(String.valueOf(Hasil));
- }
- private void lingkaranActionPerformed(java.awt.event.ActionEvent evt) {
- double Jari = Double.parseDouble(jarijari.getText());
- double phi = 3.14;
- double Hasil = phi*(Jari*Jari);
- hasillingkaran.setText(String.valueOf(Hasil));
- }
- public static void main(String[] args) {
- 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(Luas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Luas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Luas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Luas.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 Luas().setVisible(true);
- }
- });
- }
- // Variables declaration – do not modify
- private javax.swing.JTextField alas;
- private javax.swing.JTextField hasillingkaran;
- private javax.swing.JTextField hasilpersegipanjang;
- private javax.swing.JTextField hasilsegitiga;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel10;
- private javax.swing.JLabel jLabel11;
- private javax.swing.JLabel jLabel12;
- private javax.swing.JLabel jLabel13;
- private javax.swing.JLabel jLabel14;
- private javax.swing.JLabel jLabel15;
- private javax.swing.JLabel jLabel16;
- private javax.swing.JLabel jLabel17;
- private javax.swing.JLabel jLabel18;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel23;
- private javax.swing.JLabel jLabel24;
- private javax.swing.JLabel jLabel25;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JLabel jLabel6;
- private javax.swing.JLabel jLabel7;
- private javax.swing.JLabel jLabel8;
- private javax.swing.JLabel jLabel9;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPanel jPanel2;
- private javax.swing.JTextField jTextField10;
- private javax.swing.JTextField jTextField11;
- private javax.swing.JTextField jTextField12;
- private javax.swing.JTextField jTextField7;
- private javax.swing.JTextField jTextField8;
- private javax.swing.JTextField jTextField9;
- private javax.swing.JTextField jarijari;
- private javax.swing.JTextField lebar;
- private javax.swing.JButton lingkaran;
- private javax.swing.JTextField panjang;
- private javax.swing.JButton pesegi;
- private javax.swing.JButton segitiga;
- private javax.swing.JTextField tinggi;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement