import java.awt.*;
import java.awt.event.*;
public class kotak extends Frame{
kotak(){
super("Menggambar Objek Kotak");
addWindowListener(JE);
setSize(310,150);
setVisible(true);
}
public void paint(Graphics Gambar){
Gambar.setColor(Color.BLUE);
Gambar.drawRect(50, 50, 70, 70);
Gambar.fillRect(200, 50, 70, 70);
}
JendelaEvent JE = new JendelaEvent();
public class JendelaEvent extends WindowAdapter{
public void windowClosing(WindowEvent wc){
dispose();
System.exit(1);
}
}
}
Buat class test untuk memanggil method tersebut
public class test {
public static void main(String[] args) { kotak ok = new kotak(); } }
Tampilan output
Tidak ada komentar:
Posting Komentar