You are on page 1of 3

Contoh program GUI :

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author Rudi

*/

import javax.swing.*;

import java.awt.*;

import javax.swing.UIManager.*;

public class ContohGUI extends JFrame

Container konten = getContentPane();

private JLabel lblNama = new JLabel("Username : ");

private JTextField txtNama = new JTextField();

private JLabel lblAlamat = new JLabel("Password : ");

private JTextField txtAlamat = new JTextField();

private JButton btnOK = new JButton("Login");

private JButton btnCancel = new JButton("Reset");

public ContohGUI()

{
setTitle("Contoh GUI");

setSize(600,400);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLocationRelativeTo(null);

konten.setLayout(null);

lblNama.setBounds(10,10,100,25);

konten.add(lblNama);

txtNama.setBounds(130,10,200,25);

konten.add(txtNama);

lblAlamat.setBounds(10,50,100,25);

konten.add(lblAlamat);

txtAlamat.setBounds(130,50,200,25);

konten.add(txtAlamat);

btnOK.setBounds(160,200,100,25);

konten.add(btnOK);

btnCancel.setBounds(300,200,100,25);

konten.add(btnCancel);

} //Akhir Konstruktor

public static void main(String[] ar)

//Membuat Look and Feel Java Nimbus

try{

UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");

}
catch (UnsupportedLookAndFeelException e) {

catch (ClassNotFoundException e){

catch (InstantiationException e) {

catch (IllegalAccessException e) {

new ContohGUI();

Output program GUI :

You might also like