-->

Program Tebak Acak Berbasis Java Gui

Sore sobat Bloger, udah lama nih BLOG gak pernah di buka hampir berlumut nih kayanya udah kaya hutan rimbun, yang tak berpenghuni karna terlalu lama libur kuliah. Langsung aja bloger ane mau share tugas kuliah berbasis java

Buat Desaind Seperti Ini





Bahan Bahannya

JButton btnAcak;
JButton btnTebak;
JLabel jLabel1;
JTextField txtAcak;
JTextField txtAngka;
JTextField txtTebak;

Codingan Awal

public class Tugas2_Java_111100042 extends javax.swing.JFrame {
private CustomThread cThread;
private int counter;

    class CustomThread extends Thread {

        private int changingVariable;
        private boolean flag = true;

        public CustomThread(JTextField tf) {
        }

        public void setFlagValue(boolean flag) {
            this.flag = flag;
        }

        @Override
        public void run() {
            while (flag) {
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {

                        int angka = (int) (Math.random() * 10);
                        txtAcak.setText("" + angka);
                        txtAngka.setText("" + angka);
                    }
                });
                try {
                    Thread.sleep(35);
                } catch (InterruptedException ie) {
                    ie.printStackTrace();
                }
            }
        }
 }

 public Tugas2_Java_111100042() {
        initComponents();
         counter = 0;
        setLocationRelativeTo(null);
    }


Codingan   JButton btnAcak;



Codingan   JButton btnTebak;

  private void btnTebakActionPerformed(java.awt.event.ActionEvent evt) {                                        
     
        cThread.setFlagValue(false);
        txtAcak.setText("?");
        counter = 0;
        btnAcak.setText("Acak");
        {
            String bilAcak = txtAngka.getText();
            String bilTebak = txtTebak.getText();
            int IN1 = Integer.parseInt(bilAcak);
            int IN2 = Integer.parseInt(bilTebak);

            if (IN1 == IN2) {
                int exitApp = JOptionPane.showConfirmDialog(null, "Yes... Yes...\n"
                        +"Luar Biasa...  \n "
                        + "Tebakan Anda Benar!\n\n"
                        + "Coba Lagi?",
                        "Konfirmasi", JOptionPane.YES_NO_OPTION);
                if (exitApp == JOptionPane.NO_OPTION) {
                    System.exit(0);
                }
            }
            if (IN1 < IN2) {
                int exitApp = JOptionPane.showConfirmDialog(null, "you Lost.....! \n\n "
                        + "Coba Lagi?",
                        "Konfirmasi", JOptionPane.YES_NO_OPTION);
                if (exitApp == JOptionPane.NO_OPTION) {
                    System.exit(0);
                }
            }
            if (IN1 > IN2) {
                int exitApp = JOptionPane.showConfirmDialog(null, "you lost Boss...! \n\n "
                        + "Coba Lagi?",
                        "Konfirmasi", JOptionPane.YES_NO_OPTION);
                if (exitApp == JOptionPane.NO_OPTION) {
                    System.exit(0);
                }
            }
        }
    }     

Saat Program Runing                  


















Sekian Dulu Bloger Semoga Bermanfaat Program Tebak Acak Berbasis Java Gui
LihatTutupKomentar
Cancel