Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Java GUI Bangundatar

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 10

Nama : ARIS HIDAYAT NIM : 11650014

FrameBangunDatar.java
package bangundatar; /** * Nama : Aris Hidayat Nim : 11650014 * * @author AB2631VK */ public class FrameBagunDatar extends javax.swing.JFrame { public FrameBagunDatar() { initComponents(); } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { LuasL = new javax.swing.JTabbedPane(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); panjang = new javax.swing.JTextField(); lebar = new javax.swing.JTextField(); jToggleButton1 = new javax.swing.JToggleButton(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); LuasPP = new javax.swing.JTextField(); KelilingPP = new javax.swing.JTextField(); jPanel2 = new javax.swing.JPanel(); jLabel5 = new javax.swing.JLabel(); jarijari = new javax.swing.JTextField(); jToggleButton2 = new javax.swing.JToggleButton(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); LuasO = new javax.swing.JTextField(); KelilingO = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); LuasL.setBackground(new java.awt.Color(153, 255, 0)); LuasL.setForeground(new java.awt.Color(255, 0, 0)); jPanel1.setBackground(new java.awt.Color(153, 255, 0)); jLabel1.setText("Panjang"); jLabel2.setText("Lebar"); jToggleButton1.setText("Hitung Luas dan Keliling"); jToggleButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jToggleButton1ActionPerformed(evt); }

}); jLabel3.setText("Luas"); jLabel4.setText("Keliling"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(29, 29, 29) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN G, false) .addComponent(jToggleButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN G) .addComponent(jLabel1) .addComponent(jLabel2)) .addGap(22, 22, 22) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN G, false) .addComponent(lebar, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE) .addComponent(panjang))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN G) .addComponent(jLabel3) .addComponent(jLabel4)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN G, false) .addComponent(LuasPP) .addComponent(KelilingPP, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)))) .addContainerGap(50, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(20, 20, 20) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI NE) .addComponent(jLabel1)

.addComponent(panjang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI NE) .addComponent(jLabel2) .addComponent(lebar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(28, 28, 28) .addComponent(jToggleButton1) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI NE) .addComponent(jLabel3) .addComponent(LuasPP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI NE) .addComponent(jLabel4) .addComponent(KelilingPP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(32, Short.MAX_VALUE)) ); LuasL.addTab("PersegiPanjang", jPanel1); jPanel2.setBackground(new java.awt.Color(255, 255, 153)); jLabel5.setText("Jari-jari"); jToggleButton2.setText("Hitung Luas dan Keliling"); jToggleButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jToggleButton2ActionPerformed(evt); } }); jLabel6.setText("Luas"); jLabel7.setText("Keliling"); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGap(22, 22, 22) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN G, false)

.addComponent(jToggleButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel5) .addGap(18, 18, 18) .addComponent(jarijari)) .addGroup(jPanel2Layout.createSequentialGroup() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN G) .addComponent(jLabel6) .addComponent(jLabel7)) .addGap(23, 23, 23) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN G) .addComponent(LuasO) .addComponent(KelilingO)))) .addContainerGap(47, Short.MAX_VALUE)) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGap(25, 25, 25) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI NE) .addComponent(jLabel5) .addComponent(jarijari, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(50, 50, 50) .addComponent(jToggleButton2) .addGap(18, 18, 18) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI NE) .addComponent(jLabel6) .addComponent(LuasO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI NE) .addComponent(jLabel7) .addComponent(KelilingO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(43, Short.MAX_VALUE)) ); LuasL.addTab("Lingkaran", jPanel2); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(LuasL) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(LuasL) ); pack(); }// </editor-fold> private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) { PersegiPanjang pspj = new PersegiPanjang( Integer.parseInt(panjang.getText()), Integer.parseInt(lebar.getText()) ); LuasPP.setText( String.valueOf(pspj.hitungLuas()) ); KelilingPP.setText( String.valueOf(pspj.hitungKeliling()) ); } private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) { Lingkaran ling = new Lingkaran( Integer.parseInt(jarijari.getText()) ); LuasO.setText( String.valueOf(ling.hitungLuas()) ); KelilingO.setText( String.valueOf(ling.hitungKeliling()) ); } 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(FrameBagunDatar.class.getName()).log(java.util.logging. Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(FrameBagunDatar.class.getName()).log(java.util.logging. Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(FrameBagunDatar.class.getName()).log(java.util.logging. Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(FrameBagunDatar.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 FrameBagunDatar().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JTextField KelilingO; private javax.swing.JTextField KelilingPP; private javax.swing.JTabbedPane LuasL; private javax.swing.JTextField LuasO; private javax.swing.JTextField LuasPP; 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.JLabel jLabel7; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JToggleButton jToggleButton1; private javax.swing.JToggleButton jToggleButton2; private javax.swing.JTextField jarijari; private javax.swing.JTextField lebar; private javax.swing.JTextField panjang; // End of variables declaration }

PersegiPanjang.java
package bangundatar; /** * Nama : Aris Hidayat Nim : 11650014 * * @author AB2631VK */ public class PersegiPanjang { public double panjang; public double lebar; PersegiPanjang(double p, double l) { setPanjang(p); setLebar(l); } public void setPanjang(double p) { this.panjang = p; } public void setLebar(double l) { this.lebar = l; } public double hitungLuas() { return panjang * lebar; } public double hitungKeliling() { return 2 * (panjang + lebar); } }

Lingkaran.java package bangundatar; /** * Nama : Aris Hidayat Nim : 11650014 * * @author AB2631VK */ public class Lingkaran { public double jari; Lingkaran(double r) { setJari(r); } public void setJari(double r) { this.jari = r; } public double hitungLuas() { return 3.14 * jari * jari; } public double hitungKeliling() { return 2 * 3.14 * jari; } }

RUNNING PersegiPanjang

Lingkaran

You might also like