Tugas Laporan
TUTORIAL MEMBUAT LOGIN ,KALKULATOR, GAME
Berikut adalah cara-cara membuat login pada netbeans versi8.2
A.Membuat login
1.. Buka Aplikasi Netbeans
Pertama, buka terlebih dahulu Netbeans anda.
2. Buat Project Baru
Buat project baru, kemudian pilih Java > Java Application lalu simpan. Setelah itu, beri nama Project anda tersebut.
3. Buat Class Koneksi
Buatlah Class untuk mengkoneksikan program anda tersebut dengan database MySql. Berikut sintaks defaultnya :
4. Buat Desain Form Login
Buatlah desain form Login pada umumnya dan sesuaikan dengan field database tadi. Buat 2 kolom untuk username dan password serta satu button login nya.
Kolom username buat saja menggunakan jTextField.
Kolom Password buat saja dengan jPasswordField agar password yang di ketikkan tidak terlihat.
Tombol login dengan JButton.
5. Buat Codenya
Buat code di tombol Login yang telah anda buat tadi. Caranya, klik dua kali tombol/button Login, kemudian letakkan code di situ. Anda juga bisa Klik kanan pada button Login > Events > Action > ActionPerformed.
Letakkan Sintaks untuk Login berikut :
// Tombol Login
String user = jTextField1.getText();
String password = jPasswordField1.getText();
String cekuser = null;
String cekpassword = null;
try {
Connection Connect = Koneksi.getKoneksi();
Statement st = (Statement) Connect.createStatement();
String query = "SELECT * FROM akun WHERE username = '"+user+"' AND password = '"+password+"'";
ResultSet rs = st.executeQuery(query);
while(rs.next()){
cekuser = rs.getString("username");
cekpassword = rs.getString("password");
}
rs.close();
st.close();
} catch (SQLException e){
System.out.print("Terjadi Error");
}
if(cekuser == null && cekpassword== null){
String pesan = "Username Atau Password Salah";
JOptionPane.showMessageDialog(null,pesan,"Message",
JOptionPane.INFORMATION_MESSAGE);
} else {
String pesan1 = "Login Berhasil";
JOptionPane.showMessageDialog(null,pesan1,"Message",
JOptionPane.INFORMATION_MESSAGE);
new Home() .setVisible(true);
dispose();
}
5. Save Lalu Jalankan Programnya
Sebelum menjalankan programnya, masukkan secara manual Username dan Password terlebih dahulu di tabel database yang telah dibuat tadi. isikan bebas saja, kemudian save.
Jika sudah, klik kanan file anda dan Run File.
dan hasil akhir nya akan seperti ini:
Download file: https://drive.google.com/file/d/1-HYLNbZKOxbtAcUetFWNUjS5-aepaB_B/view?usp=drivesdk
B.Membuat kalkulator
Untuk membuat kalkulator ikuti langkah-langkah berikut
Buka aplikasi Netbeans
Pilih menu file – new project
Pilih kategori java – java application
Masukan nama project, misalnya : KalkulatorGUI
Klik next maka project berhasil dibuat.
Selanjutnya pada project tersebut, klik kanan pilih new
Kemudian masukan nama class lalu klik finish.
Gambar diatas merupakan antar muka aplikasi menggunakan Jframe Form. Selanjutnya kita memilih beberapa komponen SWING untuk di drag kedalam layout aplikasi.
Komponen yang kita gunakan adalah label, button, text field dan combo box. label berfungsi untuk memberi keterangan/petunjuk pada isian form, text field sebagai form isian dan button sebagai tombol untuk memproses nilai yang dimasukan pada text field, nantinya pada komponen button kita menambahkan event actionPerformed sebagai reaksi yang dilakukan saat pengguna mengklik button tersebut.
Selain itu juga kita menggunakan combobox untuk pemilihan operasi yang ingin dikerjakan baik perkalian, pembagian, penjmlahan ataupun pengurangan. Kalian juga bisa memodifikasi dengan menambahkan operasi lainnya seperti modulus (sisa pembagian) dan eksponen (perpangkatan).
Tahap berikut kita mengatur tata letak dan desain pada aplikasinya, Secara sederhana saya membuat desain seperti berikut:
dan untuk kode nya:
Tambahkan code berikut di dalam fungsi tersebut.
if (operasi.getSelectedItem().toString().equalsIgnoreCase("Perkalian")){
int a=Integer.parseInt(bil1.getText());
int b=Integer.parseInt(bil2.getText());
int jumlah=a*b;
hasil.setText (Integer.toString (jumlah));
}
if (operasi.getSelectedItem().toString().equalsIgnoreCase("Pembagian")){
int a=Integer.parseInt(bil1.getText());
int b=Integer.parseInt(bil2.getText());
int jumlah=a/b;
hasil.setText (Integer.toString (jumlah));
}
if (operasi.getSelectedItem().toString().equalsIgnoreCase("Penjumlahan")){
int a=Integer.parseInt(bil1.getText());
int b=Integer.parseInt(bil2.getText());
int jumlah=a+b;
hasil.setText (Integer.toString (jumlah));
}
if (operasi.getSelectedItem().toString().equalsIgnoreCase("Pengurangan")){
int a=Integer.parseInt(bil1.getText());
int b=Integer.parseInt(bil2.getText());
int jumlah=a-b;
hasil.setText (Integer.toString (jumlah));
}
Dan hasil akhir nya adalah:
Download file:
c.Membuat game pada netbeans
untuk membuat game langkah pertama adalah membuat project baru
Setelah itu masuk ke tampilan baru dan klik new package pada projects
Lalu buat class baru dengan cara klik new pada projects terbaru tadi lalu klik java class
Komponen yang kita gunakan adalah label, button, text field dan combo box. label berfungsi untuk memberi keterangan/petunjuk pada isian form, text field sebagai form isian dan button sebagai tombol untuk memproses hasil yang dimasukan pada text field, nantinya pada komponen button kita menambahkan event actionPerformed sebagai reaksi yang dilakukan saat pengguna mengklik button tersebut.
Atur kotak nya sesuai dengan keinginan dan saya membuat nya seperti ini:
Dan untuk coding nya:
/*
* 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.
*/
package tic.tac;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
*
* @author WHITECODER
*/
public class tictactoe extends javax.swing.JFrame {
private String startGame = "X";
private int xCount = 0;
private int oCount = 0;
/**
* Creates new form tictactoe
*/
public tictactoe() {
initComponents();
}
private void gameScore()
{
playerx.setText(String.valueOf(xCount));
playero.setText(String.valueOf(oCount));
}
private void choose_a_Player()
{
if(startGame.equalsIgnoreCase("X"))
{
startGame = "O";
}
else
{
startGame = "X";
}
}
private void winningGame()
{
String b1 = txtbtn1.getText();
String b2 = txtbtn2.getText();
String b3 = txtbtn3.getText();
String b4 = txtbtn4.getText();
String b5 = txtbtn5.getText();
String b6 = txtbtn6.getText();
String b7 = txtbtn7.getText();
String b8 = txtbtn8.getText();
String b9 = txtbtn9.getText();
// PLAYER X CODING
if(b1 == ("X") && b2 ==("X") && b3 == ("X"))
{
JOptionPane.showMessageDialog(this, "Player X wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
xCount++;
gameScore();
txtbtn1.setBackground(Color.ORANGE);
txtbtn2.setBackground(Color.ORANGE);
txtbtn3.setBackground(Color.ORANGE);
}
if(b4 == ("X") && b5 ==("X") && b6 == ("X"))
{
JOptionPane.showMessageDialog(this, "Player X wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
xCount++;
gameScore();
txtbtn4.setBackground(Color.PINK);
txtbtn5.setBackground(Color.PINK);
txtbtn6.setBackground(Color.PINK);
}
if(b7 == ("X") && b8 ==("X") && b9 == ("X"))
{
JOptionPane.showMessageDialog(this, "Player X wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
xCount++;
gameScore();
txtbtn7.setBackground(Color.YELLOW);
txtbtn8.setBackground(Color.YELLOW);
txtbtn9.setBackground(Color.YELLOW);
}
if(b1 == ("X") && b4 ==("X") && b7 == ("X"))
{
JOptionPane.showMessageDialog(this, "Player X wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
xCount++;
gameScore();
txtbtn1.setBackground(Color.ORANGE);
txtbtn4.setBackground(Color.ORANGE);
txtbtn7.setBackground(Color.ORANGE);
}
if(b2 == ("X") && b5 ==("X") && b8 == ("X"))
{
JOptionPane.showMessageDialog(this, "Player X wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
xCount++;
gameScore();
txtbtn2.setBackground(Color.PINK);
txtbtn5.setBackground(Color.PINK);
txtbtn8.setBackground(Color.PINK);
}
if(b3 == ("X") && b6 ==("X") && b9 == ("X"))
{
JOptionPane.showMessageDialog(this, "Player X wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
xCount++;
gameScore();
txtbtn3.setBackground(Color.YELLOW);
txtbtn6.setBackground(Color.YELLOW);
txtbtn9.setBackground(Color.YELLOW);
}
if(b1 == ("X") && b5 ==("X") && b9 == ("X"))
{
JOptionPane.showMessageDialog(this, "Player X wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
xCount++;
gameScore();
txtbtn1.setBackground(Color.ORANGE);
txtbtn5.setBackground(Color.ORANGE);
txtbtn9.setBackground(Color.ORANGE);
}
if(b3 == ("X") && b5 ==("X") && b7 == ("X"))
{
JOptionPane.showMessageDialog(this, "Player X wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
xCount++;
gameScore();
txtbtn3.setBackground(Color.PINK);
txtbtn5.setBackground(Color.PINK);
txtbtn7.setBackground(Color.PINK);
}
// PLAYER O CODING
if(b1 == ("O") && b2 ==("O") && b3 == ("O"))
{
JOptionPane.showMessageDialog(this, "Player O wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
oCount++;
gameScore();
txtbtn1.setBackground(Color.ORANGE);
txtbtn2.setBackground(Color.ORANGE);
txtbtn3.setBackground(Color.ORANGE);
}
if(b4 == ("O") && b5 ==("O") && b6 == ("O"))
{
JOptionPane.showMessageDialog(this, "Player O wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
oCount++;
gameScore();
txtbtn4.setBackground(Color.PINK);
txtbtn5.setBackground(Color.PINK);
txtbtn6.setBackground(Color.PINK);
}
if(b7 == ("O") && b8 ==("O") && b9 == ("O"))
{
JOptionPane.showMessageDialog(this, "Player O wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
oCount++;
gameScore();
txtbtn7.setBackground(Color.YELLOW);
txtbtn8.setBackground(Color.YELLOW);
txtbtn9.setBackground(Color.YELLOW);
}
if(b1 == ("O") && b4 ==("O") && b7 == ("O"))
{
JOptionPane.showMessageDialog(this, "Player X wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
oCount++;
gameScore();
txtbtn1.setBackground(Color.ORANGE);
txtbtn4.setBackground(Color.ORANGE);
txtbtn7.setBackground(Color.ORANGE);
}
if(b2 == ("O") && b5 ==("O") && b8 == ("O"))
{
JOptionPane.showMessageDialog(this, "Player O wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
oCount++;
gameScore();
txtbtn2.setBackground(Color.PINK);
txtbtn5.setBackground(Color.PINK);
txtbtn8.setBackground(Color.PINK);
}
if(b3 == ("O") && b6 ==("O") && b9 == ("O"))
{
JOptionPane.showMessageDialog(this, "Player O wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
oCount++;
gameScore();
txtbtn3.setBackground(Color.YELLOW);
txtbtn6.setBackground(Color.YELLOW);
txtbtn9.setBackground(Color.YELLOW);
}
if(b1 == ("O") && b5 ==("O") && b9 == ("O"))
{
JOptionPane.showMessageDialog(this, "Player O wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
oCount++;
gameScore();
txtbtn1.setBackground(Color.ORANGE);
txtbtn5.setBackground(Color.ORANGE);
txtbtn9.setBackground(Color.ORANGE);
}
if(b3 == ("O") && b5 ==("O") && b7 == ("O"))
{
JOptionPane.showMessageDialog(this, "Player O wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
oCount++;
gameScore();
txtbtn3.setBackground(Color.PINK);
txtbtn5.setBackground(Color.PINK);
txtbtn7.setBackground(Color.PINK);
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
txtbtn1 = new javax.swing.JButton();
txtbtn2 = new javax.swing.JButton();
txtbtn3 = new javax.swing.JButton();
txtbtn4 = new javax.swing.JButton();
txtbtn5 = new javax.swing.JButton();
txtbtn6 = new javax.swing.JButton();
txtbtn7 = new javax.swing.JButton();
txtbtn8 = new javax.swing.JButton();
txtbtn9 = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
playerx = new javax.swing.JLabel();
playero = new javax.swing.JLabel();
jButton10 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("TIC TAC TOE GAME");
setResizable(false);
jPanel1.setBackground(new java.awt.Color(0, 51, 255));
jLabel1.setFont(new java.awt.Font("Segoe UI", 1, 48)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("TIC TAC TOE GAME");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(309, 309, 309)
.addComponent(jLabel1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
txtbtn1.setFont(new java.awt.Font("Segoe UI", 1, 48)); // NOI18N
txtbtn1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtbtn1ActionPerformed(evt);
}
});
txtbtn2.setFont(new java.awt.Font("Segoe UI", 1, 48)); // NOI18N
txtbtn2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtbtn2ActionPerformed(evt);
}
});
txtbtn3.setFont(new java.awt.Font("Segoe UI", 1, 48)); // NOI18N
txtbtn3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtbtn3ActionPerformed(evt);
}
});
txtbtn4.setFont(new java.awt.Font("Segoe UI", 1, 48)); // NOI18N
txtbtn4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtbtn4ActionPerformed(evt);
}
});
txtbtn5.setFont(new java.awt.Font("Segoe UI", 1, 48)); // NOI18N
txtbtn5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtbtn5ActionPerformed(evt);
}
});
txtbtn6.setFont(new java.awt.Font("Segoe UI", 1, 48)); // NOI18N
txtbtn6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtbtn6ActionPerformed(evt);
}
});
txtbtn7.setFont(new java.awt.Font("Segoe UI", 1, 48)); // NOI18N
txtbtn7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtbtn7ActionPerformed(evt);
}
});
txtbtn8.setFont(new java.awt.Font("Segoe UI", 1, 48)); // NOI18N
txtbtn8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtbtn8ActionPerformed(evt);
}
});
txtbtn9.setFont(new java.awt.Font("Segoe UI", 1, 48)); // NOI18N
txtbtn9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtbtn9ActionPerformed(evt);
}
});
jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED, java.awt.Color.lightGray, java.awt.Color.darkGray));
jLabel2.setFont(new java.awt.Font("Segoe UI", 1, 24)); // NOI18N
jLabel2.setText("Player X :");
jLabel3.setFont(new java.awt.Font("Segoe UI", 1, 24)); // NOI18N
jLabel3.setText("Player O :");
playerx.setFont(new java.awt.Font("Segoe UI", 1, 24)); // NOI18N
playerx.setForeground(new java.awt.Color(0, 102, 255));
playerx.setText("xxxxxxx");
playero.setFont(new java.awt.Font("Segoe UI", 1, 24)); // NOI18N
playero.setForeground(new java.awt.Color(0, 102, 255));
playero.setText("xxxxxxx");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(38, 38, 38)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addGap(77, 77, 77)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(playero)
.addComponent(playerx))
.addContainerGap(67, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap(63, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(playerx))
.addGap(54, 54, 54)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(playero))
.addContainerGap(74, Short.MAX_VALUE))
);
jButton10.setBackground(new java.awt.Color(153, 153, 255));
jButton10.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
jButton10.setText("RESET");
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton10ActionPerformed(evt);
}
});
jButton11.setBackground(new java.awt.Color(255, 153, 153));
jButton11.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
jButton11.setText("EXIT");
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton11ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(txtbtn1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtbtn2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(txtbtn4, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtbtn5, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(txtbtn7, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtbtn8, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtbtn3, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtbtn6, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtbtn9, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(35, 35, 35)
.addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(90, 90, 90)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(41, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(txtbtn3, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtbtn6, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtbtn1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtbtn2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtbtn4, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtbtn5, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtbtn7, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtbtn8, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtbtn9, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 23, Short.MAX_VALUE))
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtbtn1.setText(null);
txtbtn2.setText(null);
txtbtn3.setText(null);
txtbtn4.setText(null);
txtbtn5.setText(null);
txtbtn6.setText(null);
txtbtn7.setText(null);
txtbtn8.setText(null);
txtbtn9.setText(null);
txtbtn1.setBackground(Color.LIGHT_GRAY);
txtbtn2.setBackground(Color.LIGHT_GRAY);
txtbtn3.setBackground(Color.LIGHT_GRAY);
txtbtn4.setBackground(Color.LIGHT_GRAY);
txtbtn5.setBackground(Color.LIGHT_GRAY);
txtbtn6.setBackground(Color.LIGHT_GRAY);
txtbtn7.setBackground(Color.LIGHT_GRAY);
txtbtn8.setBackground(Color.LIGHT_GRAY);
txtbtn9.setBackground(Color.LIGHT_GRAY);
}
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JFrame frame = new JFrame("Exit");
if (JOptionPane.showConfirmDialog(frame, "Confirm if you want Exit",
"Tic Tac Toe",
JOptionPane.YES_NO_OPTION)== JOptionPane.YES_NO_OPTION)
{
System.exit(0);
}
}
private void txtbtn1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtbtn1.setText(startGame);
if(startGame.equalsIgnoreCase("X"))
{
txtbtn1.setForeground(Color.RED);
}
else
{
txtbtn1.setForeground(Color.MAGENTA);
}
choose_a_Player();
winningGame();
}
private void txtbtn2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtbtn2.setText(startGame);
if(startGame.equalsIgnoreCase("X"))
{
txtbtn2.setForeground(Color.RED);
}
else
{
txtbtn2.setForeground(Color.MAGENTA);
}
choose_a_Player();
winningGame();
}
private void txtbtn3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtbtn3.setText(startGame);
if(startGame.equalsIgnoreCase("X"))
{
txtbtn3.setForeground(Color.RED);
}
else
{
txtbtn3.setForeground(Color.MAGENTA);
}
choose_a_Player();
winningGame();
}
private void txtbtn4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtbtn4.setText(startGame);
if(startGame.equalsIgnoreCase("X"))
{
txtbtn4.setForeground(Color.RED);
}
else
{
txtbtn4.setForeground(Color.MAGENTA);
}
choose_a_Player();
winningGame();
}
private void txtbtn5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtbtn5.setText(startGame);
if(startGame.equalsIgnoreCase("X"))
{
txtbtn5.setForeground(Color.RED);
}
else
{
txtbtn5.setForeground(Color.MAGENTA);
}
choose_a_Player();
winningGame();
}
private void txtbtn6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtbtn6.setText(startGame);
if(startGame.equalsIgnoreCase("X"))
{
txtbtn6.setForeground(Color.RED);
}
else
{
txtbtn6.setForeground(Color.MAGENTA);
}
choose_a_Player();
winningGame();
}
private void txtbtn9ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtbtn9.setText(startGame);
if(startGame.equalsIgnoreCase("X"))
{
txtbtn9.setForeground(Color.RED);
}
else
{
txtbtn9.setForeground(Color.MAGENTA);
}
choose_a_Player();
winningGame();
}
private void txtbtn8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtbtn8.setText(startGame);
if(startGame.equalsIgnoreCase("X"))
{
txtbtn8.setForeground(Color.RED);
}
else
{
txtbtn8.setForeground(Color.MAGENTA);
}
choose_a_Player();
winningGame();
}
private void txtbtn7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtbtn7.setText(startGame);
if(startGame.equalsIgnoreCase("X"))
{
txtbtn7.setForeground(Color.RED);
}
else
{
txtbtn7.setForeground(Color.MAGENTA);
}
choose_a_Player();
winningGame();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(tictactoe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(tictactoe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(tictactoe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(tictactoe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new tictactoe().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JLabel playero;
private javax.swing.JLabel playerx;
private javax.swing.JButton txtbtn1;
private javax.swing.JButton txtbtn2;
private javax.swing.JButton txtbtn3;
private javax.swing.JButton txtbtn4;
private javax.swing.JButton txtbtn5;
private javax.swing.JButton txtbtn6;
private javax.swing.JButton txtbtn7;
private javax.swing.JButton txtbtn8;
private javax.swing.JButton txtbtn9;
// End of variables declaration
}
Dan hasil akhirnya adalah seperti ini:
Download file:https://drive.google.com/file/d/1-K6d98pJEqezz75ZI2C4NGYWR7dfsUk8/view

0 Komentar:
Posting Komentar
Berlangganan Posting Komentar [Atom]
<< Beranda