----------- coding start here -------------------
package sonihendarkuliah; import java.awt.*; import javax.swing.*; /** * * @author montox */ public class Tugas3_SoalPilihanGanda extends javax.swing.JFrame { //daftar soal dan jawaban dalam bentuk Array String[]NoxTanya={"SOAL 1: Nama Buah Iblis Monkey D.Luffy","SOAL 2: Vice Admiral Smooker tipe buah iblis nya ?","SOAL 3: Julukan dari Admiral Sengkoku adalah ?","SOAL 4: Nama pedang terbaru Roronoa Zorro adalah ?"}; String[]NoxA={"Hito-Hito No Mi model NIKA","Paramecia","Kakek peyot","Pedang Pora"}; String[]NoxB={"Buah Anggur","LOGIA","Komandan","Pedang Laser"}; String[]NoxC={"Buah Apel","Zoan","The Budha","Nogososro Sabuk Inten"}; String[]NoxD={"Buah Bibir","Hybrida pestisida","Jendral","ENMA"}; String[]NoxJWB={"a","b","c","d"}; int index = 0; /** * Creates new form Tugas3_SoalPilihanGanda */ public Tugas3_SoalPilihanGanda() { initComponents(); this.setResizable(false); // agar windows tidak bisa di perbesar (Maximize / Non Sizeable) // Agar posisi windows di tengah layar, mengambil ukuran layar, butuh import java.awt.*; Dimension layar = Toolkit.getDefaultToolkit().getScreenSize(); // Agar posisi windows di tengah layar, membuat titik x dan y int x = layar.width / 2 - this.getSize().width / 2; int y = layar.height / 2 - this.getSize().height / 2; this.setLocation(x, y); muncul(0); NoxButtonPrev_.setVisible(false); //agar tombol Prev hilang dari layar awal } public void muncul(int i){ NoxFieldPertanyaan_.setText(NoxTanya[i]); NoxButtonA_.setText("A. "+NoxA[i]); NoxButtonB_.setText("B. "+NoxB[i]); NoxButtonC_.setText("C. "+NoxC[i]); NoxButtonD_.setText("D. "+NoxD[i]); } public void Cek_NoxJWB(String m){ if (m.equals(NoxJWB[index])) { JOptionPane.showMessageDialog(rootPane, "BENAR"); } else { JOptionPane.showMessageDialog(rootPane, "Jawaban kamu SALAH !!!", "SALAH", HEIGHT); } } /** * 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. */ private void NoxButtonA_MousePressed(java.awt.event.MouseEvent evt) { // Tombol berubah warna ketika di klik NoxButtonA_.setBackground(Color.red); } private void NoxButtonA_MouseReleased(java.awt.event.MouseEvent evt) { // Tombol berubah warna ketika klik di lepas NoxButtonA_.setBackground(Color.LIGHT_GRAY); } private void NoxButtonB_MouseReleased(java.awt.event.MouseEvent evt) { // Tombol berubah warna ketika klik di lepas NoxButtonB_.setBackground(Color.LIGHT_GRAY); } private void NoxButtonC_MouseReleased(java.awt.event.MouseEvent evt) { // Tombol berubah warna ketika klik di lepas NoxButtonC_.setBackground(Color.LIGHT_GRAY); } private void NoxButtonD_MouseReleased(java.awt.event.MouseEvent evt) { // Tombol berubah warna ketika klik di lepas NoxButtonD_.setBackground(Color.LIGHT_GRAY); } private void NoxButtonD_MousePressed(java.awt.event.MouseEvent evt) { // Tombol berubah warna ketika di klik NoxButtonD_.setBackground(Color.red); } private void NoxButtonB_MousePressed(java.awt.event.MouseEvent evt) { // Tombol berubah warna ketika di klik NoxButtonB_.setBackground(Color.red); } private void NoxButtonC_MousePressed(java.awt.event.MouseEvent evt) { // Tombol berubah warna ketika di klik NoxButtonC_.setBackground(Color.red); } private void NoxButtonNext_MouseEntered(java.awt.event.MouseEvent evt) { // Tombol berubah warna ketika Cursor berada diatas tombol (Mouse Over) NoxButtonNext_.setBackground(Color.BLUE); } private void NoxButtonNext_MouseExited(java.awt.event.MouseEvent evt) { // Tombol berubah warna ketika Cursor keluar dari area tombol (Mouse Out) NoxButtonNext_.setBackground(Color.LIGHT_GRAY); } private void NoxButtonPrev_MouseEntered(java.awt.event.MouseEvent evt) { // Tombol berubah warna ketika Cursor berada diatas tombol (Mouse Over) NoxButtonPrev_.setBackground(Color.BLUE); } private void NoxButtonPrev_MouseExited(java.awt.event.MouseEvent evt) { // Tombol berubah warna ketika Cursor keluar dari area tombol (Mouse Out) NoxButtonPrev_.setBackground(Color.LIGHT_GRAY); } private void NoxButtonA_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Cek_NoxJWB("a"); } private void NoxButtonB_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Cek_NoxJWB("b"); } private void NoxButtonC_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Cek_NoxJWB("c"); } private void NoxButtonD_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Cek_NoxJWB("d"); } private void NoxButtonNext_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: index++; muncul(index); if (index == 1) { NoxButtonPrev_.setVisible(true); } if (index == 3) { NoxButtonNext_.setVisible(false); } else { NoxButtonNext_.setVisible(true); } } private void NoxButtonPrev_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: index--; muncul(index); if (index == 0) { NoxButtonPrev_.setVisible(false); } else { NoxButtonPrev_.setVisible(true); NoxButtonNext_.setVisible(true); } } private void NoxAboutActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: JOptionPane.showMessageDialog(rootPane, "Matkul Pemgorgraman JAVA Lanjut \n" + "PTI 4B \n" + "Soni Hendarkanto \n\n" + "Tugas 3 Membuat Program Soal Pilihan Ganda Sederhana \n" + "Sabtu 4 Maret 2023 \n\n" + "Hanya bisa copas dan (sangat) sedikit modif dari coding yg ditunjukkan oleh pak dosen Rozi \n" + "Belum bisa membuat variasi yg lebih complex \n\n" + "---One Piece Fans---", "Tentang Program ini", HEIGHT); } // Variables declaration - do not modify private javax.swing.JButton NoxAbout; private javax.swing.JButton NoxButtonA_; private javax.swing.JButton NoxButtonB_; private javax.swing.JButton NoxButtonC_; private javax.swing.JButton NoxButtonD_; private javax.swing.JButton NoxButtonNext_; private javax.swing.JButton NoxButtonPrev_; private javax.swing.JTextField NoxFieldPertanyaan_; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JSeparator jSeparator1; // End of variables declaration }
---- end of code ----






