日期:2014-05-20  浏览次数:20720 次

【求助】同一个程序在cmd中是死循环,在netbeans中正常~
各位大侠早上好!
昨天我跟着书写了一个Applet的小程序,实现的是输入1打印直线,输入2打印矩形,输入3打印圆。然后还可以输入重复打印的次数
程序如下:

************************Choice.java*****************************
import java.awt.Graphics;
import javax.swing.*;

public class Choice extends JApplet
{
  int choice;
   
  public void init()
  {
  String str1;
  str1=JOptionPane.showInputDialog("输入1画直线\n输入2画矩形\n输入3画圆");
  choice=Integer.parseInt(str1);
  }
   
   
   
  public void paint(Graphics g)
  {
  super.paint(g);
   
   
  String str2;
  int number;
   
  str2=JOptionPane.showInputDialog("输入需要重复的次数:");
  number=Integer.parseInt(str2);
   
  for(int i=0; i<10; i++)
  {
  switch(choice)
  {
  case 1:
  g.drawLine(15, 15, 300, 15+i*15);
  break;
   
  case 2:
  g.drawRect(15+i*20, 15+i*8, 50+i*10, 50+i*10);
  break;
   
  case 3:
  g.drawOval(15+i*20, 15+i*8, 50+i*10, 50+i*10);
  break;
   
  default:
  g.drawString("无效的输入!", 50, 15+i*15);
  }
  }
  }
}


************************b.html*****************************
<html>
  <APPLET code="Choice.class" width=500 height=500></APPLET>
</html>
   

这同一个程序在netbeans里边一切正常,但是在cmd执行的时候却出现了死循环:
str2=JOptionPane.showInputDialog("输入需要重复的次数:");
这一句不停的弹出在桌面的中间,如果将这个对话框拖到其他位置,依然会弹出来~
只有关了appletviwer.exe才能终止,我的cmd是在compmgmt.msc中修改了用户的默认初始路径~

不知道这个是什么原因~

------解决方案--------------------
你重新编译一下试试~我用cmd和eclipse都好使~
------解决方案--------------------
先重装下jdk试试!
------解决方案--------------------
在CMD中调用是加上 -Djava.awt.headless=true
java -Djava.awt.headless=true classname