Advertisement
stevennathaniel

Enkapsulasi Dalam Pemrograman Java SE

Feb 3rd, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.97 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package latihanbasic2;
  7.  
  8. /**
  9.  *
  10.  * @author steven
  11.  */
  12.  
  13.  
  14. class Murid{
  15.    
  16.    
  17.     private String nama;
  18.    
  19.     private int Id;
  20.    
  21.    
  22.     public void setNama(String nama){
  23.        
  24.         this.nama=nama;
  25.        
  26.        
  27.     }
  28.    
  29.     public String getNama(){
  30.        
  31.         return nama;
  32.     }
  33.    
  34.    
  35.     public void setId(int Id){
  36.        
  37.         this.Id=Id;
  38.     }
  39.    
  40.    
  41.     public int getID(){
  42.    
  43.     return Id;
  44. }
  45.    
  46.    
  47.    
  48. }
  49.  
  50.  
  51. public class BasicClass3 extends javax.swing.JFrame {
  52.  
  53.     /**
  54.      * Creates new form BasicClass3
  55.      */
  56.     public BasicClass3() {
  57.         initComponents();
  58.     }
  59.  
  60.     /**
  61.      * This method is called from within the constructor to initialize the form.
  62.      * WARNING: Do NOT modify this code. The content of this method is always
  63.      * regenerated by the Form Editor.
  64.      */
  65.     @SuppressWarnings("unchecked")
  66.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  67.     private void initComponents() {
  68.  
  69.         jButton1 = new javax.swing.JButton();
  70.  
  71.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  72.  
  73.         jButton1.setText("jButton1");
  74.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  75.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  76.                 jButton1ActionPerformed(evt);
  77.             }
  78.         });
  79.  
  80.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  81.         getContentPane().setLayout(layout);
  82.         layout.setHorizontalGroup(
  83.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  84.             .addGroup(layout.createSequentialGroup()
  85.                 .addContainerGap()
  86.                 .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
  87.                 .addContainerGap(189, Short.MAX_VALUE))
  88.         );
  89.         layout.setVerticalGroup(
  90.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  91.             .addGroup(layout.createSequentialGroup()
  92.                 .addContainerGap()
  93.                 .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
  94.                 .addContainerGap(207, Short.MAX_VALUE))
  95.         );
  96.  
  97.         pack();
  98.     }// </editor-fold>                        
  99.  
  100.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  101.         // TODO add your handling code here:
  102.        
  103.        
  104.         Murid obj = new Murid();
  105.        
  106.        
  107.         obj.setNama("Ibnu");
  108.        
  109.         obj.setId(01);
  110.        
  111.        
  112.         System.out.println("Nama : " + obj.getNama());
  113.        
  114.         System.out.println("ID : " + obj.getID());
  115.        
  116.     }                                        
  117.  
  118.     /**
  119.      * @param args the command line arguments
  120.      */
  121.     public static void main(String args[]) {
  122.         /* Set the Nimbus look and feel */
  123.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  124.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  125.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  126.          */
  127.         try {
  128.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  129.                 if ("Nimbus".equals(info.getName())) {
  130.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  131.                     break;
  132.                 }
  133.             }
  134.         } catch (ClassNotFoundException ex) {
  135.             java.util.logging.Logger.getLogger(BasicClass3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  136.         } catch (InstantiationException ex) {
  137.             java.util.logging.Logger.getLogger(BasicClass3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  138.         } catch (IllegalAccessException ex) {
  139.             java.util.logging.Logger.getLogger(BasicClass3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  140.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  141.             java.util.logging.Logger.getLogger(BasicClass3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  142.         }
  143.         //</editor-fold>
  144.  
  145.         /* Create and display the form */
  146.         java.awt.EventQueue.invokeLater(new Runnable() {
  147.             public void run() {
  148.                 new BasicClass3().setVisible(true);
  149.             }
  150.         });
  151.     }
  152.  
  153.     // Variables declaration - do not modify                    
  154.     private javax.swing.JButton jButton1;
  155.     // End of variables declaration                  
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement