Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Kotak
- {
- /*
- Dengan satuan centimeter
- */
- private int tinggi;
- private int lebar;
- public Kotak(int tinggi, int lebar){
- this.tinggi = tinggi;
- this.lebar = lebar;
- }
- public int getLuas(){
- return tinggi*lebar;
- }
- public int getTinggi(){
- return tinggi;
- }
- public int getLebar(){
- return lebar;
- }
- public void setTinggi(int tinggi){
- this.tinggi = tinggi;
- }
- public void setLebar(int lebar){
- this.lebar = lebar;
- }
- }
- //==================================
- import javax.swing.*;
- import java.awt.*;
- import java.awt.Color;
- public class MainClass extends JFrame
- {
- public static int cmToPxl = 5;
- public MainClass()
- {
- Container con = getContentPane();
- con.setBackground(Color.WHITE);
- con.setLayout(new FlowLayout());
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- public void paint(Graphics gr)
- {
- super.paint(gr);
- Kotak kotak1 = new Kotak(10,10);
- gr.setColor(Color.RED);
- gr.drawRect(50,50,
- kotak1.getTinggi() * cmToPxl,
- kotak1.getLebar() * cmToPxl);
- }
- public static void main(String[] args)
- {
- MainClass frame = new MainClass();
- frame.setSize(200, 200);
- frame.setVisible(true);
- /*
- Kotak kotak1 = new Kotak(10, 15);
- kotak1.setTinggi(20);
- System.out.println(kotak1.getTinggi());
- System.out.println(kotak1.getLuas());
- kotak1.getLuas2();
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement