SHARE
TWEET

Pertemuan5

a guest Sep 17th, 2019 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Kotak
  2. {
  3.     /*
  4.     Dengan satuan centimeter
  5.     */
  6.     private int tinggi;
  7.     private int lebar;
  8.    
  9.     public Kotak(int tinggi, int lebar){
  10.         this.tinggi = tinggi;
  11.         this.lebar = lebar;
  12.     }
  13.        
  14.     public int getLuas(){      
  15.         return tinggi*lebar;
  16.     }
  17.     public int getTinggi(){
  18.         return tinggi;
  19.     }
  20.    
  21.     public int getLebar(){
  22.         return lebar;
  23.     }
  24.     public void setTinggi(int tinggi){
  25.         this.tinggi = tinggi;
  26.     }
  27.     public void setLebar(int lebar){
  28.         this.lebar = lebar;
  29.     }  
  30. }
  31. //==================================
  32. import javax.swing.*;
  33. import java.awt.*;
  34. import java.awt.Color;
  35. public class MainClass extends JFrame
  36. {
  37.     public static int cmToPxl = 5;
  38.     public MainClass()
  39.     {
  40.         Container con = getContentPane();
  41.         con.setBackground(Color.WHITE);    
  42.         con.setLayout(new FlowLayout());               
  43.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  44.     }
  45.     public void paint(Graphics gr)
  46.     {      
  47.         super.paint(gr);
  48.         Kotak kotak1 = new Kotak(10,10);
  49.        
  50.         gr.setColor(Color.RED);
  51.         gr.drawRect(50,50,
  52.                     kotak1.getTinggi() * cmToPxl,
  53.                     kotak1.getLebar() * cmToPxl);
  54.            
  55.     }
  56.     public static void main(String[] args)
  57.     {
  58.         MainClass frame = new MainClass();
  59.         frame.setSize(200, 200);
  60.         frame.setVisible(true);
  61.         /*
  62.         Kotak kotak1 = new Kotak(10, 15);
  63.         kotak1.setTinggi(20);
  64.         System.out.println(kotak1.getTinggi());
  65.         System.out.println(kotak1.getLuas());
  66.         kotak1.getLuas2();
  67.         */
  68.     }
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top