Selamat pagi sobat kota ilmu komputer yang menyempatkan diri mampir ke blog saya, pada posting kali ini saya akan memberikan tutorial membuat software GUI berupa kalkulator sederhana dengan software Eclipse. Semoga artikel ini bermanfaat buat saya dan para pembaca semuanya. Nanti hasil dari pemrograman ini nampak seperti dibawah ini :
Langsung saja, pertama buka Eclipse kalian, then click "create new Java Project". Setelah itu buat class baru dengan nama "Kalkulator". Atur class Kalkulator agar menjadi subclass dari kelas JFrame.
Syntaxnya adalah seperti ini :
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class Kalkulator extends JFrame {
// deklarasi variabel
protected static final Object JButton = null;
private JPanel contentPane;
private JTextField textField;
private Float operasi1;
private Float operasi2;
private String tanda;
private String back;
//main aplication
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Kalkulator frame = new Kalkulator();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
// Membuat frame
public Kalkulator() {
// sintax untuk pembuatan frame
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBackground(new Color(23, 7, 231));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
//label judul
JLabel lblKalkulator = new JLabel("Kalkulator Sederhana");
lblKalkulator.setForeground(new Color(236, 236, 20));
lblKalkulator.setFont(new Font("Tempus Sans ITC", Font.BOLD, 30));
// label untuk tulisan hasil
JLabel lblHasil = new JLabel("Hasil");
lblHasil.setForeground(new Color(236, 236, 20));
lblHasil.setFont(new Font("Comic Sans MS", Font.BOLD, 14));
// display hasil dan operasi kalkulator
textField = new JTextField();
textField.setBackground(Color.WHITE);
textField.setFont(new Font("Tempus Sans ITC", Font.BOLD, 17));
textField.setColumns(10);
// Syntax untuk menampilkan angka (0-9)
JButton satu = new JButton("1");
satu.addMouseListener(new MouseAdapter() {
@Override
// syntax untuk menjalankan aksi,jika button angka di klik maka akan tampil di layer display angka tersebut
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"1");
}
});
satu.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton dua = new JButton("2");
dua.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"2");
}
});
dua.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton tiga = new JButton("3");
tiga.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"3");
}
});
tiga.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton empat = new JButton("4");
empat.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"4");
}
});
empat.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton lima = new JButton("5");
lima.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"5");
}
});
lima.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton enam = new JButton("6");
enam.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"6");
}
});
enam.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton tujuh = new JButton("7");
tujuh.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"7");
}
});
tujuh.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton delapan = new JButton("8");
delapan.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"8");
}
});
delapan.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton sembilan = new JButton("9");
sembilan.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"9");
}
});
sembilan.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton nol = new JButton("0");
nol.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"0");
}
});
nol.setFont(new Font("Tahoma", Font.BOLD, 11));
// syntax untuk button operasi matematika(+,_,/,* dan =) dan juga tombol backspace dan clean
JButton perkalian = new JButton("x");
perkalian.addMouseListener(new MouseAdapter() {
// syntax untuk menjalankan fungsi dari tombol yaitu operasi matematika pada kalkulator dan kemudian di tampilkan pada display
@Override
public void mouseClicked(MouseEvent arg0) {
operasi1=Float.valueOf(textField.getText());
tanda="*";
textField.setText("");
}
});
perkalian.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton pembagian = new JButton("/");
pembagian.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
operasi1=Float.valueOf(textField.getText());
tanda="/";
textField.setText("");
}
});
pembagian.setFont(new Font("Tahoma", Font.PLAIN, 11));
JButton penjumlahan = new JButton("+");
penjumlahan.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
operasi1=Float.valueOf(textField.getText());
tanda="+";
textField.setText("");
}
});
penjumlahan.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton pengurangan = new JButton("-");
pengurangan.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
operasi1=Float.valueOf(textField.getText());
tanda="-";
textField.setText("");
}
});
pengurangan.setFont(new Font("Tahoma", Font.BOLD, 11));
// syntax sama dengan
JButton samadengan = new JButton("=");
samadengan.addMouseListener(new MouseAdapter() {
@Override
//syntax untuk operasi samadengan dan di tampilkan pada display kalkulator (textfield)
public void mouseClicked(MouseEvent arg0) {
operasi2=Float.valueOf(textField.getText());
if(tanda.equals("*"))
operasi1=operasi1*operasi2;
else if(tanda.equals("/"))
operasi1=operasi1/operasi2;
else if(tanda.equals("+"))
operasi1=operasi1+operasi2;
else if(tanda.equals("-"))
operasi1=operasi1-operasi2;
textField.setText(String.valueOf(operasi1));
}
});
samadengan.setFont(new Font("Tahoma", Font.BOLD, 11));
// syntax untuk backspace, menghapus angka per satu digit
JButton btnBa = new JButton("Backspace");
btnBa.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
int x;
back=textField.getText();
x=back.length();
back=back.substring(0,x-1);
textField.setText(back);
}
});
btnBa.setFont(new Font("Tahoma", Font.BOLD, 9));
// syntax untuk menghapus angka yang telah di tekan secara keseluruah (clear)
JButton btnC = new JButton("C");
btnC.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText("");
}
});
btnC.setFont(new Font("Tahoma", Font.BOLD, 10));
// syntax untuk menampilankan footer
JLabel lblTmd = new JLabel("Created by Azka");
lblTmd.setForeground(new Color(236, 236, 20));
lblTmd.setFont(new Font("Simplified Arabic Fixed", Font.BOLD, 12));
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(lblHasil)
.addComponent(textField, GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(satu)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(dua)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(tiga))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(empat)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(lima)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(enam))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(tujuh)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(delapan)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(sembilan))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(nol)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(btnBa)))
.addGap(23)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(2)
.addComponent(perkalian)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(pengurangan, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(penjumlahan)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(2)
.addComponent(pembagian, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE))
.addComponent(btnC))
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(samadengan)))
.addContainerGap(169, Short.MAX_VALUE))))
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(60)
.addComponent(lblKalkulator, GroupLayout.PREFERRED_SIZE, 350, GroupLayout.PREFERRED_SIZE) //350 merupakan panjang text field judul
.addContainerGap(119, Short.MAX_VALUE))
.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
.addContainerGap(274, Short.MAX_VALUE)
.addComponent(lblTmd)
.addGap(22))
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblKalkulator)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(lblHasil)
.addGap(15)
.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(23)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(satu)
.addComponent(dua)
.addComponent(tiga)
.addComponent(perkalian)
.addComponent(pengurangan))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(empat)
.addComponent(lima)
.addComponent(enam)
.addComponent(pembagian, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(tujuh)
.addComponent(delapan)
.addComponent(sembilan)
.addComponent(penjumlahan))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(nol)
.addComponent(btnBa)
.addComponent(btnC)))
.addComponent(samadengan, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
.addComponent(lblTmd))
);
contentPane.setLayout(gl_contentPane);
}
}
Sekian tutorialnya, jika ada pertanyaan bisa tanya melalui kolom komentar.
Langsung saja, pertama buka Eclipse kalian, then click "create new Java Project". Setelah itu buat class baru dengan nama "Kalkulator". Atur class Kalkulator agar menjadi subclass dari kelas JFrame.
Syntaxnya adalah seperti ini :
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class Kalkulator extends JFrame {
// deklarasi variabel
protected static final Object JButton = null;
private JPanel contentPane;
private JTextField textField;
private Float operasi1;
private Float operasi2;
private String tanda;
private String back;
//main aplication
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Kalkulator frame = new Kalkulator();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
// Membuat frame
public Kalkulator() {
// sintax untuk pembuatan frame
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBackground(new Color(23, 7, 231));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
//label judul
JLabel lblKalkulator = new JLabel("Kalkulator Sederhana");
lblKalkulator.setForeground(new Color(236, 236, 20));
lblKalkulator.setFont(new Font("Tempus Sans ITC", Font.BOLD, 30));
// label untuk tulisan hasil
JLabel lblHasil = new JLabel("Hasil");
lblHasil.setForeground(new Color(236, 236, 20));
lblHasil.setFont(new Font("Comic Sans MS", Font.BOLD, 14));
// display hasil dan operasi kalkulator
textField = new JTextField();
textField.setBackground(Color.WHITE);
textField.setFont(new Font("Tempus Sans ITC", Font.BOLD, 17));
textField.setColumns(10);
// Syntax untuk menampilkan angka (0-9)
JButton satu = new JButton("1");
satu.addMouseListener(new MouseAdapter() {
@Override
// syntax untuk menjalankan aksi,jika button angka di klik maka akan tampil di layer display angka tersebut
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"1");
}
});
satu.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton dua = new JButton("2");
dua.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"2");
}
});
dua.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton tiga = new JButton("3");
tiga.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"3");
}
});
tiga.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton empat = new JButton("4");
empat.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"4");
}
});
empat.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton lima = new JButton("5");
lima.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"5");
}
});
lima.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton enam = new JButton("6");
enam.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"6");
}
});
enam.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton tujuh = new JButton("7");
tujuh.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"7");
}
});
tujuh.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton delapan = new JButton("8");
delapan.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"8");
}
});
delapan.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton sembilan = new JButton("9");
sembilan.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"9");
}
});
sembilan.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton nol = new JButton("0");
nol.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText(textField.getText()+"0");
}
});
nol.setFont(new Font("Tahoma", Font.BOLD, 11));
// syntax untuk button operasi matematika(+,_,/,* dan =) dan juga tombol backspace dan clean
JButton perkalian = new JButton("x");
perkalian.addMouseListener(new MouseAdapter() {
// syntax untuk menjalankan fungsi dari tombol yaitu operasi matematika pada kalkulator dan kemudian di tampilkan pada display
@Override
public void mouseClicked(MouseEvent arg0) {
operasi1=Float.valueOf(textField.getText());
tanda="*";
textField.setText("");
}
});
perkalian.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton pembagian = new JButton("/");
pembagian.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
operasi1=Float.valueOf(textField.getText());
tanda="/";
textField.setText("");
}
});
pembagian.setFont(new Font("Tahoma", Font.PLAIN, 11));
JButton penjumlahan = new JButton("+");
penjumlahan.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
operasi1=Float.valueOf(textField.getText());
tanda="+";
textField.setText("");
}
});
penjumlahan.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton pengurangan = new JButton("-");
pengurangan.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
operasi1=Float.valueOf(textField.getText());
tanda="-";
textField.setText("");
}
});
pengurangan.setFont(new Font("Tahoma", Font.BOLD, 11));
// syntax sama dengan
JButton samadengan = new JButton("=");
samadengan.addMouseListener(new MouseAdapter() {
@Override
//syntax untuk operasi samadengan dan di tampilkan pada display kalkulator (textfield)
public void mouseClicked(MouseEvent arg0) {
operasi2=Float.valueOf(textField.getText());
if(tanda.equals("*"))
operasi1=operasi1*operasi2;
else if(tanda.equals("/"))
operasi1=operasi1/operasi2;
else if(tanda.equals("+"))
operasi1=operasi1+operasi2;
else if(tanda.equals("-"))
operasi1=operasi1-operasi2;
textField.setText(String.valueOf(operasi1));
}
});
samadengan.setFont(new Font("Tahoma", Font.BOLD, 11));
// syntax untuk backspace, menghapus angka per satu digit
JButton btnBa = new JButton("Backspace");
btnBa.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
int x;
back=textField.getText();
x=back.length();
back=back.substring(0,x-1);
textField.setText(back);
}
});
btnBa.setFont(new Font("Tahoma", Font.BOLD, 9));
// syntax untuk menghapus angka yang telah di tekan secara keseluruah (clear)
JButton btnC = new JButton("C");
btnC.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
textField.setText("");
}
});
btnC.setFont(new Font("Tahoma", Font.BOLD, 10));
// syntax untuk menampilankan footer
JLabel lblTmd = new JLabel("Created by Azka");
lblTmd.setForeground(new Color(236, 236, 20));
lblTmd.setFont(new Font("Simplified Arabic Fixed", Font.BOLD, 12));
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(lblHasil)
.addComponent(textField, GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(satu)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(dua)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(tiga))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(empat)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(lima)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(enam))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(tujuh)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(delapan)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(sembilan))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(nol)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(btnBa)))
.addGap(23)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(2)
.addComponent(perkalian)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(pengurangan, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(penjumlahan)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(2)
.addComponent(pembagian, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE))
.addComponent(btnC))
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(samadengan)))
.addContainerGap(169, Short.MAX_VALUE))))
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(60)
.addComponent(lblKalkulator, GroupLayout.PREFERRED_SIZE, 350, GroupLayout.PREFERRED_SIZE) //350 merupakan panjang text field judul
.addContainerGap(119, Short.MAX_VALUE))
.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
.addContainerGap(274, Short.MAX_VALUE)
.addComponent(lblTmd)
.addGap(22))
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblKalkulator)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(lblHasil)
.addGap(15)
.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(23)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(satu)
.addComponent(dua)
.addComponent(tiga)
.addComponent(perkalian)
.addComponent(pengurangan))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(empat)
.addComponent(lima)
.addComponent(enam)
.addComponent(pembagian, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(tujuh)
.addComponent(delapan)
.addComponent(sembilan)
.addComponent(penjumlahan))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(nol)
.addComponent(btnBa)
.addComponent(btnC)))
.addComponent(samadengan, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
.addComponent(lblTmd))
);
contentPane.setLayout(gl_contentPane);
}
}
Sekian tutorialnya, jika ada pertanyaan bisa tanya melalui kolom komentar.