我正在java中创建一个应用程序。我对设计问题很感兴趣。它有一个类
class UserInterface //class that
extends JFrame // and
implements KeyListener{
//so when it runs it can listen to key inputs.
public void keyPressed(...){
// if pressed 1 : I make an object of DoProcessingAndGetChoice class
// and start its process() function. please see below.
}
.....
}
现在我将此输入发送到另一个类
class DoProcessingAndGetChoice{
....
public void process(){
// got three results.
// **I want to ask to the user which is the best result ?**
// How to ask ?
// UserInterace class (see above) would get all keyStrokes.
// should i implement "keyListener"
// would both methods (here keyPressed() and UserInterface's keyListener())
//would be called
}
}
此DoDoProcessingAndGetChoice :: process()执行一些处理并生成一些结果,并且它想要询问用户关于结果的“某事”。 (比如什么是最好的答案。)因为所有的击键都会转到UserInterface类我将如何从UserInterface类keyPressed方法提供此函数的输入。
UserInterface 类是仅存在于桌面上的gui框架。
如果输入转到UserInterface类,我可以将它发送到 DoProcessingAndGetChoice 类,并且这样的函数 proceed()可以继续furthur