2017-10-03 3 views
0

Ich möchte mein Programm wiederholen, wenn Sie den Button "Nochmal" drücken Alles funktioniert, aber ich kenne den Code nicht, um das Programm von Anfang an zu wiederholen. btw ist ein zufälliger Zahlengenerator mit eigenem Eingang.JOptionPane repeat Programm durch Drücken einer Taste

package main; 

import java.util.Random; 

import javax.swing.*; 


public class randomNumberGen { 

    public static void main(String[] args) { 
     Object[] options1 = { "Nochmal", "Quit" }; 

     int eingabe = Integer.parseInt(JOptionPane.showInputDialog("Von 0 bis: ", null)); 

     Random rn = new Random(); 

     for(int i =0; i < 1; i++) 
     { 
      int answer =rn.nextInt(eingabe) + 1; 

      JPanel antwort = new JPanel(); 
      antwort.add(new JLabel("Deine Zahl lautet: " + answer)); 

      int result = JOptionPane.showOptionDialog(null, antwort, "RNG", 
        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, 
        null, options1, null); 
      if (result == JOptionPane.YES_OPTION){ 
       //what to put into here? 
      } 
     } 

    } 
} 
+0

'für (int i = 0; i <1; i ++)' ist wahrscheinlich nicht notwendig. – notyou

Antwort

0

gerade setzen:

main(args); 

Sie Ihre Logik, obwohl aus dem Hauptverfahren erhalten sollen.

Verwandte Themen