class GameFrame
/*
* 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 project;
import java.applet.Applet;
import java.applet.AudioClip;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import project.GamePanel;
/**
*
* @author user
*/
public class GameFrame extends javax.swing.JFrame {
AudioClip bunyii=Applet.newAudioClip(getClass().getResource("/snd/start.mid"));
/**
* Creates new form NewJFrame
*/
JFrame frame;
public GameFrame() {
initComponents();
}
/**
* 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">//GEN-BEGIN:initComponents
private void initComponents() {
start = new javax.swing.JButton();
exit = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("dena pertiwi 120155201057");
setMaximumSize(new java.awt.Dimension(0, 0));
setMinimumSize(new java.awt.Dimension(600, 595));
getContentPane().setLayout(null);
start.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
start.setForeground(new java.awt.Color(255, 204, 102));
start.setText("start");
start.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
startActionPerformed(evt);
}
});
getContentPane().add(start);
start.setBounds(80, 300, 110, 70);
exit.setBackground(new java.awt.Color(204, 204, 204));
exit.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
exit.setForeground(new java.awt.Color(255, 204, 102));
exit.setText("exit");
exit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitActionPerformed(evt);
}
});
getContentPane().add(exit);
exit.setBounds(400, 300, 110, 70);
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
jLabel3.setForeground(new java.awt.Color(0, 204, 255));
jLabel3.setText("usut");
getContentPane().add(jLabel3);
jLabel3.setBounds(310, 120, 130, 50);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 51, 204));
jLabel2.setText("game");
getContentPane().add(jLabel2);
jLabel2.setBounds(140, 120, 150, 60);
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/wa1.jpg"))); // NOI18N
getContentPane().add(jLabel1);
jLabel1.setBounds(0, 0, 610, 595);
pack();
}// </editor-fold>//GEN-END:initComponents
private void startActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startActionPerformed
// TODO add your handling code here:
new GamePanel().setVisible(true);
dispose();
}//GEN-LAST:event_startActionPerformed
private void exitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitActionPerformed
// TODO add your handling code here:
JOptionPane.showMessageDialog(frame, "are you sure!");
dispose();
}//GEN-LAST:event_exitActionPerformed
/**
* @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(GameFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(GameFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(GameFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(GameFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GameFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton exit;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JButton start;
// End of variables declaration//GEN-END:variables
}
class GamePanel
/**
*
*
*/
package project;
import java.applet.Applet;
import javax.swing.JFrame;
import java.util.Random;
import javax.swing.JOptionPane;
import javax.swing.*;
import java.applet.AudioClip;
import java.awt.event.KeyEvent;
public class GamePanel extends javax.swing.JFrame{
AudioClip bunyi=Applet.newAudioClip(getClass().getResource("/snd/Speech Off.wav"));
AudioClip bunyi1=Applet.newAudioClip(getClass().getResource("/snd/game_over.wav"));
AudioClip bunyi2=Applet.newAudioClip(getClass().getResource("/snd/good.wav"));
AudioClip bunyi3=Applet.newAudioClip(getClass().getResource("/snd/start.mid"));
JFrame frame;
public GamePanel() {
bunyi3.play();
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
lblYou = new javax.swing.JLabel();
lblCpu = new javax.swing.JLabel();
txtY1 = new javax.swing.JTextField();
txtC1 = new javax.swing.JTextField();
txtY2 = new javax.swing.JTextField();
txtY3 = new javax.swing.JTextField();
txtY4 = new javax.swing.JTextField();
txtY5 = new javax.swing.JTextField();
txtY8 = new javax.swing.JTextField();
txtC2 = new javax.swing.JTextField();
txtC3 = new javax.swing.JTextField();
txtC4 = new javax.swing.JTextField();
txtC5 = new javax.swing.JTextField();
txtC8 = new javax.swing.JTextField();
jPanel3 = new javax.swing.JPanel();
b1 = new javax.swing.JLabel();
g1 = new javax.swing.JLabel();
k1 = new javax.swing.JLabel();
b2 = new javax.swing.JLabel();
g2 = new javax.swing.JLabel();
k2 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
btnLanjut = new javax.swing.JButton();
btnUlang = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
exit = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("dena pertiwi 120155201057");
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
formKeyPressed(evt);
}
});
jPanel1.setBackground(new java.awt.Color(255, 102, 204));
jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, null, new java.awt.Color(153, 0, 102), null, null));
jPanel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
lblYou.setFont(new java.awt.Font("Calibri", 1, 24)); // NOI18N
lblYou.setText("YOU");
lblCpu.setFont(new java.awt.Font("Calibri", 1, 24)); // NOI18N
lblCpu.setText("CPU");
txtY1.setBackground(new java.awt.Color(51, 153, 255));
txtY1.setFont(new java.awt.Font("seevaa9", 1, 24)); // NOI18N
txtY1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtY1.setEnabled(false);
txtC1.setBackground(new java.awt.Color(255, 51, 102));
txtC1.setFont(new java.awt.Font("DigifaceWide", 1, 24)); // NOI18N
txtC1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtC1.setEnabled(false);
txtY2.setBackground(new java.awt.Color(255, 102, 255));
txtY2.setFont(new java.awt.Font("DigifaceWide", 1, 24)); // NOI18N
txtY2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtY2.setEnabled(false);
txtY3.setBackground(new java.awt.Color(255, 102, 0));
txtY3.setFont(new java.awt.Font("DigifaceWide", 1, 24)); // NOI18N
txtY3.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtY3.setEnabled(false);
txtY4.setBackground(new java.awt.Color(0, 255, 102));
txtY4.setFont(new java.awt.Font("DigifaceWide", 1, 24)); // NOI18N
txtY4.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtY4.setEnabled(false);
txtY5.setBackground(new java.awt.Color(204, 255, 0));
txtY5.setFont(new java.awt.Font("DigifaceWide", 1, 24)); // NOI18N
txtY5.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtY5.setEnabled(false);
txtY8.setFont(new java.awt.Font("DigifaceWide", 1, 24)); // NOI18N
txtY8.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtY8.setText("0");
txtY8.setEnabled(false);
txtC2.setBackground(new java.awt.Color(255, 255, 51));
txtC2.setFont(new java.awt.Font("DigifaceWide", 1, 24)); // NOI18N
txtC2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtC2.setEnabled(false);
txtC3.setBackground(new java.awt.Color(51, 51, 255));
txtC3.setFont(new java.awt.Font("DigifaceWide", 1, 24)); // NOI18N
txtC3.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtC3.setEnabled(false);
txtC4.setBackground(new java.awt.Color(0, 204, 204));
txtC4.setFont(new java.awt.Font("DigifaceWide", 1, 24)); // NOI18N
txtC4.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtC4.setEnabled(false);
txtC5.setBackground(new java.awt.Color(255, 153, 153));
txtC5.setFont(new java.awt.Font("DigifaceWide", 1, 24)); // NOI18N
txtC5.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtC5.setEnabled(false);
txtC8.setFont(new java.awt.Font("DigifaceWide", 1, 24)); // NOI18N
txtC8.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtC8.setText("0");
txtC8.setEnabled(false);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(lblYou)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 70, Short.MAX_VALUE)
.addComponent(txtY1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(txtY2, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(txtY3, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(txtY4, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(txtY5, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(lblCpu)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtC1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(txtC2, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(txtC3, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(txtC4, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(txtC5, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(80, 80, 80)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtY8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtC8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtY1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblYou)
.addComponent(txtY2, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtY3, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtY4, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtY5, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtY8, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblCpu)
.addComponent(txtC1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtC2, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtC3, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtC4, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtC5, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtC8, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(13, Short.MAX_VALUE))
);
jPanel3.setBackground(new java.awt.Color(51, 153, 255));
jPanel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, null, new java.awt.Color(204, 0, 255), null, null));
b1.setBackground(new java.awt.Color(51, 204, 255));
b1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/b2.png"))); // NOI18N
b1.addAncestorListener(new javax.swing.event.AncestorListener() {
public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
}
public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
b1AncestorAdded(evt);
}
public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
}
});
b1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
b1MouseClicked(evt);
}
});
g1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/g2.png"))); // NOI18N
g1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
g1MouseClicked(evt);
}
});
k1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/k2.png"))); // NOI18N
k1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
k1MouseClicked(evt);
}
});
b2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/cb2.png"))); // NOI18N
g2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/cg2.png"))); // NOI18N
k2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/ck2.png"))); // NOI18N
jLabel1.setFont(new java.awt.Font("365sweetmuffin", 1, 48)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 0, 204));
jLabel1.setText("VS");
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1)
.addGap(280, 280, 280))
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addComponent(k1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(k2))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addComponent(b1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(b2))
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(g1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(g2)))))
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 67, Short.MAX_VALUE)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(b2)
.addComponent(b1))
.addGap(44, 44, 44)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(g2, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(g1, javax.swing.GroupLayout.Alignment.TRAILING))
.addGap(42, 42, 42)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(k2)
.addComponent(k1))
.addContainerGap())
);
btnLanjut.setFont(new java.awt.Font("seevaa9", 1, 14)); // NOI18N
btnLanjut.setForeground(new java.awt.Color(255, 0, 204));
btnLanjut.setText("LANJUT");
btnLanjut.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnLanjutActionPerformed(evt);
}
});
btnLanjut.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
btnLanjutKeyPressed(evt);
}
});
btnUlang.setFont(new java.awt.Font("seevaa9", 1, 14)); // NOI18N
btnUlang.setForeground(new java.awt.Color(204, 0, 204));
btnUlang.setText("ULANG");
btnUlang.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnUlangActionPerformed(evt);
}
});
jLabel3.setFont(new java.awt.Font("CR룡체C", 1, 24)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 0, 204));
jLabel3.setText("CPU");
jLabel2.setFont(new java.awt.Font("CR룡체C", 1, 24)); // NOI18N
jLabel2.setForeground(new java.awt.Color(0, 204, 255));
jLabel2.setText("YOU");
exit.setFont(new java.awt.Font("seevaa9", 1, 14)); // NOI18N
exit.setForeground(new java.awt.Color(255, 153, 0));
exit.setText("EXIT");
exit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(29, 29, 29)
.addComponent(jLabel2)
.addGap(71, 71, 71)
.addComponent(btnLanjut, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnUlang)
.addGap(67, 67, 67)
.addComponent(exit, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(60, 60, 60)
.addComponent(jLabel3)
.addGap(23, 23, 23)))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 33, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(25, 25, 25))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(39, Short.MAX_VALUE)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnUlang, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnLanjut, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(exit, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
boolean status = false;
private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed
}//GEN-LAST:event_formKeyPressed
public void Reset(String ket)
{
b1.setBounds(21, 12,b1.getWidth(),b1.getHeight());
g1.setBounds(21, 118,g1.getWidth(),g1.getHeight());
k1.setBounds(21, 224,k1.getWidth(),k1.getHeight());
b2.setBounds(600, 12,b2.getWidth(),b2.getHeight());
g2.setBounds(600, 118,g2.getWidth(),g2.getHeight());
k2.setBounds(600, 224,k2.getWidth(),k2.getHeight());
status = false;
if (ket.equals("ALL"))
{
txtC1.setText("");
txtC2.setText("");
txtC3.setText("");
txtC4.setText("");
txtC5.setText("");
txtC8.setText("0");
txtY1.setText("");
txtY2.setText("");
txtY3.setText("");
txtY4.setText("");
txtY5.setText("");
txtY8.setText("0");
}
}
public int Acak()
{
int nilai = 0;
Random acak = new Random();
int n = 3;
nilai = acak.nextInt(n + 1);
return nilai;
}
public void Lawan(String ket)
{
int nilaiAcak = 0;
nilaiAcak = Acak();
if (nilaiAcak == 1)
{
b2.setBounds(367, 118,b2.getWidth(),b2.getHeight());
if (ket.equals("k"))
{
Nilai("1");
}
else if (ket.equals("g"))
{
Nilai("0");
}
}
else if (nilaiAcak == 2)
{
g2.setBounds(367, 118,g2.getWidth(),g2.getHeight());
if (ket.equals("b"))
{
Nilai("1");
}
else if (ket.equals("k"))
{
Nilai("0");
}
}
else
{
k2.setBounds(367, 118,k2.getWidth(),k2.getHeight());
if (ket.equals("g"))
{
Nilai("1");
}
else if (ket.equals("b"))
{
Nilai("0");
}
}
}
public void Nilai(String ket)
{
if (ket.equals("1"))
{
if (txtY1.getText().equals(""))
{
txtY1.setText("10");
txtC1.setText("0");
txtY8.setText(String.valueOf(Integer.parseInt(txtY8.getText())+10));
}
else if (txtY2.getText().equals(""))
{
txtY2.setText("10");
txtC2.setText("0");
txtY8.setText(String.valueOf(Integer.parseInt(txtY8.getText())+10));
}
else if (txtY3.getText().equals(""))
{
txtY3.setText("10");
txtC3.setText("0");
txtY8.setText(String.valueOf(Integer.parseInt(txtY8.getText())+10));
}
else if (txtY4.getText().equals(""))
{
txtY4.setText("10");
txtC4.setText("0");
txtY8.setText(String.valueOf(Integer.parseInt(txtY8.getText())+10));
}
else if (txtY5.getText().equals(""))
{
txtY5.setText("10");
txtC5.setText("0");
txtY8.setText(String.valueOf(Integer.parseInt(txtY8.getText())+10));
if(Integer.parseInt(txtY8.getText()) < Integer.parseInt(txtC8.getText())){
bunyi3.stop();
bunyi1.play();
JOptionPane.showMessageDialog(frame, "game over");
}
else if(Integer.parseInt(txtY8.getText()) > Integer.parseInt(txtC8.getText())){
bunyi3.stop();
bunyi2.play();
JOptionPane.showMessageDialog(frame, "you win");
}
Reset("ALL");
}
}
else
{
if (txtY1.getText().equals(""))
{
txtY1.setText("0");
txtC1.setText("10");
txtC8.setText(String.valueOf(Integer.parseInt(txtC8.getText())+10));
}
else if (txtY2.getText().equals(""))
{
txtY2.setText("0");
txtC2.setText("10");
txtC8.setText(String.valueOf(Integer.parseInt(txtC8.getText())+10));
}
else if (txtY3.getText().equals(""))
{
txtY3.setText("0");
txtC3.setText("10");
txtC8.setText(String.valueOf(Integer.parseInt(txtC8.getText())+10));
}
else if (txtY4.getText().equals(""))
{
txtY4.setText("0");
txtC4.setText("10");
txtC8.setText(String.valueOf(Integer.parseInt(txtC8.getText())+10));
}
else if (txtY5.getText().equals(""))
{
txtY5.setText("0");
txtC5.setText("10");
txtC8.setText(String.valueOf(Integer.parseInt(txtC8.getText())+10));
if(Integer.parseInt(txtY8.getText()) < Integer.parseInt(txtC8.getText())){
bunyi3.stop();
bunyi1.play();
JOptionPane.showMessageDialog(frame, "game over");
}
else if(Integer.parseInt(txtY8.getText()) > Integer.parseInt(txtC8.getText())){
bunyi3.stop();
bunyi2.play();
JOptionPane.showMessageDialog(frame, "you win");
}
bunyi3.play();
Reset("ALL");
}
}
}
private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
}//GEN-LAST:event_formWindowActivated
private void btnUlangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUlangActionPerformed
bunyi3.play();
Reset("ALL");
}//GEN-LAST:event_btnUlangActionPerformed
private void btnLanjutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLanjutActionPerformed
Reset("");
}//GEN-LAST:event_btnLanjutActionPerformed
private void b1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b1MouseClicked
if (status == false)
{
b1.setBounds(245, 118,b1.getWidth(),b1.getHeight());
status = true;
bunyi.play();
Lawan("b");
}
}//GEN-LAST:event_b1MouseClicked
private void g1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_g1MouseClicked
if (status == false)
{
g1.setBounds(245, 118,g1.getWidth(),g1.getHeight());
status = true;
bunyi.play();
Lawan("g");
}
}//GEN-LAST:event_g1MouseClicked
private void k1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_k1MouseClicked
if (status == false)
{
k1.setBounds(245, 118,k1.getWidth(),k1.getHeight());
status = true;
bunyi.play();
Lawan("k");
}
}//GEN-LAST:event_k1MouseClicked
private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
Reset("ALL");
}//GEN-LAST:event_formWindowOpened
private void b1AncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_b1AncestorAdded
// TODO add your handling code here:
}//GEN-LAST:event_b1AncestorAdded
private void btnLanjutKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btnLanjutKeyPressed
// TODO add your handling code here:
}//GEN-LAST:event_btnLanjutKeyPressed
private void exitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitActionPerformed
// TODO add your handling code here:
bunyi3.stop();
JOptionPane.showMessageDialog(frame, "good bye!");
dispose();
}//GEN-LAST:event_exitActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel b1;
private javax.swing.JLabel b2;
private javax.swing.JButton btnLanjut;
private javax.swing.JButton btnUlang;
private javax.swing.JButton exit;
private javax.swing.JLabel g1;
private javax.swing.JLabel g2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel3;
private javax.swing.JLabel k1;
private javax.swing.JLabel k2;
private javax.swing.JLabel lblCpu;
private javax.swing.JLabel lblYou;
private javax.swing.JTextField txtC1;
private javax.swing.JTextField txtC2;
private javax.swing.JTextField txtC3;
private javax.swing.JTextField txtC4;
private javax.swing.JTextField txtC5;
private javax.swing.JTextField txtC8;
private javax.swing.JTextField txtY1;
private javax.swing.JTextField txtY2;
private javax.swing.JTextField txtY3;
private javax.swing.JTextField txtY4;
private javax.swing.JTextField txtY5;
private javax.swing.JTextField txtY8;
// End of variables declaration//GEN-END:variables
public void keyTyped(KeyEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void keyPressed(KeyEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void keyReleased(KeyEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
Komentar
Posting Komentar