我有這個GUI程序,我試圖基本上覆制Windows CMD。由於我在這個程序中有很多功能,我決定將部分代碼放在不同的類中。但它沒有迴應。Java沒有從其他類的響應
if(command.size()<2 && command.size()>0) {
switch(command.get(0)) {
case "dt":
getDateTime a = new getDateTime();
a.Start();
break;
// other case(s) down below
}
}
這裏是geDateTime類
public class getDateTime {
public static void Start() {
Terminal t = new Terminal();
try {
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date date = new Date();
String s = dateFormat.format(date).toString();
t.print(s);
}catch(Exception e){ e.printStackTrace(); }
}
}
這裏是打印();在主類...
public static void print(String s) {
Color c = Color.WHITE; // prints white text to JFrame
Style style = output.addStyle("Style", null);
StyleConstants.setForeground(style, c);
try{
document.insertString(document.getLength(), s, style);
}catch(Exception e){e.printStackTrace();}
}
現在,當我輸入命令訪問getDateTime類,程序凍結,我不能輸入任何內容。但是,如果我只是把getDateTime類放入主類的void中,它就可以正常工作;但是這將會是一個問題,因爲一些函數可能會有數百行代碼,因此將所有內容都放到主類中。
程序死機時不會產生錯誤。
您可以在pastebin.com上添加終端類的代碼嗎?您是否嘗試過使用調試器? – neowulf33
@ neowulf33 http://pastebin.com/7Z1WuMJF – Arc