gpt4 book ai didi

Java 应用程序 GUI 在不同类中寻求输入

转载 作者:行者123 更新时间:2023-12-02 08:11:27 26 4
gpt4 key购买 nike

我正在用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() 可以继续进行进一步。

最佳答案

在不了解更多信息的情况下,我最好的猜测是您应该查看 actionskey bindings如图herehere .

关于Java 应用程序 GUI 在不同类中寻求输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7362401/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com