我正在尝试构建一个应用程序,当按下我的DJ MIDI控制器上的特定键时,计时器开始运行。
为此,我实现了Receiver类,如下所示:
public class MidiInputReceiver implements Receiver {
public String name;
public static ArrayList<byte[]> midiMessageArrayList = new ArrayList<>();
public String deckA = "";
public String deckB = "";
boolean checkFirstTime = true;
public MidiInputReceiver(String name) {
this.name = name;
}
@Override
public void send(MidiMessage msg, long timeStamp) {
if (checkFirstTime == true) {
Properties mainProperties = new Properties();
FileInputStream fileInStream;
String path = "./properties/midi_keys.properties";
try {
File file = new File("./properties/midi_keys.properties");
if (file.exists() == true) {
fileInStream = new FileInputStream(file);
mainProperties.load(fileInStream);
fileInStream.close();
deckA = mainProperties.getProperty("KEY_A_DECK");
deckB = mainProperties.getProperty("KEY_B_DECK");
checkFirstTime = false;
}
}
catch (FileNotFoundException ex) {
ex.printStackTrace();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
byte[] aMsg = msg.getMessage();
midiMessageArrayList.add(aMsg);
if (!deckA.equals("") && !deckB.equals("")) {
int msgKey = aMsg[1];
int msgAction = aMsg[2];
if(msgKey == Integer.parseInt(deckA) && msgAction == 127) {
MainFXMLController.HandleTimer();
}
}
}
public static ArrayList getArrayMessage() {
return midiMessageArrayList;
}
@Override
public void close() {}
}
但是当我尝试调用MainFXMLController类(控制主GUI和计时器的类)中的HandleTimer()方法时,出现错误,因为“无法引用非静态方法HandleTimer()来自静态上下文”。
有什么方法可以调用HandleTimer()方法并启动计时器,而无需创建MainFXMLController类的新实例?
谢谢大家!