在用户输入他们的选择后,该程序似乎再次提供相同的选择,然后完全冻结。它只设置在那里给他们一次选项(我相信),然后按照下面的选择。相反,它似乎恢复到顶部,然后由于某种奇怪的原因冻结。尝试了一段时间,但无济于事。
public void init() //Initialize method {
setSize(1000, 800); //Set size
Container c = getContentPane();
c.setBackground(Color.GREEN); //Set background
}
public void paint(Graphics g) {
super.paint(g); //Start paint method
g.setFont(new Font("Veranda", Font.PLAIN, 20));
g.setColor(Color.BLACK);
g.drawString("Hello", 250, 25); //top display message
String number = JOptionPane.showInputDialog("Would you like a custom loop count or an infinite? 1. Custom 2. Infinite"); //test choice
n = Integer.parseInt(number);
while (n>0 || n<2)
if (n==1) {
String number2 = JOptionPane.showInputDialog("How many times would you like to loop?");
integer = Integer.parseInt(number2);
while (integer>0)
while (x < integer) {
g.drawString("hi", 200, y);
x+=1;
y = y+40; //test
}//end while
}//end if
else if (n==2) {
while (true); //im aware this is an endless loop. Can't find anything more stable for an endless one, so its just there for now..
}//end if
else;
g.drawString("Please pick a valid choice", 200, 200);
}//end paint
}//end