Java没有来自其他类的响应
我有一个GUI程序,我试图基本上复制windows CMD。因为我在这个程序中有很多特性,所以我决定将部分代码放在不同的类中。但它没有反应Java没有来自其他类的响应,java,class,user-interface,jframe,void,Java,Class,User Interface,Jframe,Void,我有一个GUI程序,我试图基本上复制windows CMD。因为我在这个程序中有很多特性,所以我决定将部分代码放在不同的类中。但它没有反应 if(command.size()<2 && command.size()>0) { switch(command.get(0)) { case "dt": getDateTime a = new getDateTime(
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
}
}
这是指纹();在主类中无效
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类放在主类中的一个空中,它就可以正常工作;但是如果将所有内容都放在主类中,这将是一个问题,因为某些函数可能有数百行代码
程序冻结时不会产生错误。在前面的代码段中,代码试图创建新的终端,而不是使用现有的终端 试试这个:
private static void print() {
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date date = new Date();
String s = dateFormat.format(date).toString();
print(s);
}
在访问方法中:
case "dt":
print();
break;
更新:在旁注中,尽可能避免静电干扰。一般来说,这是一种坏习惯。请参见能否在pastebin.com上添加Terminal类的代码?你试过使用调试器吗?@neowulf33谢谢你的回答,只是一个简单的问题。这是在一个单独的类上,还是在主类terminal.java中?print方法将在terminal类中。
在旁注中,尽可能避免静态。一般来说,这是一种不好的做法。
?静态是编程的关键部分…@neowulf33如果一个空洞有几百行长,我能做些什么吗?我将方法的大小保持在30行左右,这不会迫使用户在阅读方法时滚动。您可以将大的void方法分解为较小的void方法。
case "dt":
print();
break;