我想使用joptionpane,但它返回到命令

vulvrdjw  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(290)
import java.util.Scanner;
import javax.swing.JOptionPane;

public class Auto5 {
    public char pilihan;
    public String nama = "ayam";
    public String nim = "190";

    Scanner in = new Scanner(System.in);

      public static void cls() {
        try {
            new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
        } catch (Exception E) {
            System.out.println(E);
        }
     }

public void cariNama() {
        String nama = "ayam";
        String abjad = " abcdefghijklmnopqrstuvwxyz1234567890";
        String namaOutput = "";

        for (int i = 0; i < nama.length(); i++) {

            char hurufnama = nama.charAt(i); 
            for (int j = 0; j < abjad.length(); j++) {
                char hurufabjad = abjad.charAt(j); 
                if (hurufnama == hurufabjad) {
                    JOptionPane.showMessageDialog(null,hurufabjad);
                    namaOutput = namaOutput + hurufabjad;
                    JOptionPane.showMessageDialog(null,"\nNama:"+namaOutput);

                    //i got confused here
                   //btw its indonesian, lanjutkan?means continue?, konfirmasi=confirmation
                    int lanjutx =JOptionPane.showOptionDialog(null, "Lanjutkan?", "Konfirmasi", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
                        if (lanjutx == JOptionPane.YES_OPTION) 
                        break;
                        else
                        JOptionPane.showMessageDialog(null,hurufabjad);

                }
            }

    }
}
    public void cariNIM() {
        String angka = "0123456789";
        String nimOutput = "";
        Scanner in = new Scanner(System.in);
        String nim = "190";

        for (int i = 0; i < nim.length(); i++) {
            char angkaNIM = nim.charAt(i); 
            for (int j = 0; j < angka.length(); j++) {
                char satuAngka = angka.charAt(j); 
                if (angkaNIM == satuAngka) {
                    JOptionPane.showMessageDialog(null,satuAngka);
                    nimOutput = nimOutput + satuAngka;
                    JOptionPane.showMessageDialog(null,"NIM:"+nimOutput);

                    //i got confused here
//btw its indonesian, lanjutkan?means continue?, konfirmasi=confirmation
int lanjuty =JOptionPane.showOptionDialog(null, "Lanjutkan?", "Konfirmasi", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
                        if (lanjuty == JOptionPane.YES_OPTION) 
                        break;
                        else
                        JOptionPane.showMessageDialog(null,satuAngka);

            }
        }
    }
}
    public static void main(String[] args) {
        String nama = "ayam";
        String nim = "190";

        Auto1 auto_ = new Auto1();

        JOptionPane.showMessageDialog(null,"Nama: "+nama);
        JOptionPane.showMessageDialog(null,"\nNIM: "+nim);

        int namaiya=JOptionPane.showOptionDialog(null,"Cari Nama?","Keluar",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE, null, null, null);
        if(namaiya==JOptionPane.YES_OPTION){
        auto_.cariNama();
        }
        int nimiya=JOptionPane.showOptionDialog(null,"Cari NIM?","Keluar",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE, null, null, null);    
        if(nimiya==JOptionPane.YES_OPTION){
        auto_.cariNIM();
        }

            JOptionPane.showMessageDialog(null,"Nama dan NIM telah ditemukan\n");
            JOptionPane.showMessageDialog(null,"Nama: ayam");
            JOptionPane.showMessageDialog(null,"NIM: 190");

    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题