开发者

Java Application GUI seeking input in different classes

I am making an application in java. and i am strucked at Design issue. It has a class

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. 
     }
.....
}

now i send this input to another class

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
}
}

This DoDoProcessingAndGetChoice::process() does some processing and generates some reults and it wants to ask the user "something" about the result. (like what is the best answer.) As all keystrokes would go to UserInterface class How would i from UserInterface class keyPressed Method supply the inputs to this function.

UserInterface class is the gui frame that is only present on the desktop.

开发者_如何学Go

if the input goes to UserInterface class can i some how send it to the DoProcessingAndGetChoice class and in such a way that this function proceed() can proceed furthur.


Without knowing more, my best guess is that you should look into actions and key bindings as show here and here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜