gpt4 book ai didi

java - 如何从文本区域创建到其他阶段的超链接

转载 作者:行者123 更新时间:2023-12-01 14:36:15 25 4
gpt4 key购买 nike

在 JAVAFX 应用程序中,有一个文本区域,我想在其中创建超链接,以便单击该超链接后,新阶段将在运行时打开(其中将包含一个文本区域),并且当前文本将进入主文本区域将被转发到新阶段的新文本区域。这可以实现吗?有什么建议吗?

我的应用程序中有以下代码,其中“actLogTArea”是文本区域,我想在其中提供超链接/按钮,并且我想将来自主文本区域的文本传输到新文本区域,您可以建议吗如何改变这一点?

new Thread(new Runnable() {
protected Logger logger = Logger.getLogger(UnixBoxTask.class.getName());

public void run() {

try {

String user = userName;
String pass = pwd;
String host = lanIP;

JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);
//session.setHostKeyAlias(sshHostKey);

java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);


session.setPassword(pass);
session.connect();

BufferedReader br = new BufferedReader(new FileReader(scriptPath));
String line;
String command_cd = "";


// Build unix command list separated by semicolon
while ((line = br.readLine()) != null) {
if (line.charAt(0) == '.' && line.charAt(1) == '/') {
line = ". " + line;
}
command_cd += line + ";";
}

br.close();
ArrayList nameofthreads = new ArrayList();

StringBuilder outputFromUnix = new StringBuilder();

this.logger.info("Command = " + command_cd);
Channel channel = session.openChannel("shell");

if (taskName.equalsIgnoreCase(increseSRB) || taskName.equalsIgnoreCase(decreseSRB)) {
String keyValueFile = DeploymentTaskController.getInstance().scriptFilePath + "\\" + taskName + "_KeyValue.txt";
buildParameterList(keyValueFile, taskName);
ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp");
channelSftp.connect();
copyFiles(channelSftp, new File(keyValueFile), GlobalValues.getValueFromProps(taskName, "Build Path", LoginController.environment) + "/" + taskName);
channelSftp.disconnect();
}

channel.connect();
PrintStream commander = new PrintStream(channel.getOutputStream(), true);
commander.println(command_cd);
commander.println("exit;");
commander.close();
BufferedWriter bw = null;
InputStream outputstream_from_the_channel = channel.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(outputstream_from_the_channel));
bw = new BufferedWriter(new FileWriter(resultLogFile.getAbsolutePath(), true), 20000);


String jarOutput;
int count=0;

while ((jarOutput = reader.readLine()) != null) {
this.logger.info("Status Update = " + jarOutput);

bw.write(jarOutput);
if (jarOutput.contains("Test")) {
nameofthreads.add(jarOutput);
continue;

}

bw.newLine();
bw.flush();
outputFromUnix.append(jarOutput).append("\n");
// Display in activity log area in realtime.
if (DeploymentTaskController.actLogTArea != null && !taskName.equalsIgnoreCase(connectBundle)) {
final String outputStr = outputFromUnix.toString();
Platform.runLater(new Runnable() {
@Override
public void run() {

**DeploymentTaskController.actLogTArea.setText(outputStr);
DeploymentTaskController.actLogTArea.end();**

}
});
}

}




bw.close();
reader.close();


do {
Thread.sleep(1000);
} while (!channel.isEOF());



channel.disconnect();
session.disconnect();

Thread.sleep(1000);

} catch (JSchException jex) {
System.out.println("JSCH Exception : " + jex.getMessage());
} catch (Exception ex) {


System.out.println("General Exception JSCH Block : " + ex.getMessage() + AppUtil.stack2string(ex));
}


}
}).start();

最佳答案

这很容易实现。实际上,超链接并不是用于此目的的东西。不要忽视 javafx 和 html。

要做什么:

  1. 创建一个按钮(如果需要,可以创建超链接)
  2. setOnAction(new EventHandler<ActionEvent>(){})并将以下代码添加到函数中:
  3. new Stage(new Scene(new Group(new TextArea(ta.textProperty().bind(ta.textProperty()))))).show() ,其中 ta - 是第一阶段的文本区域。

您必须注意,JavaFX 是一种面向对象的 GUI 技术,当您有访问权或链接时,您可以随时创建新的 javaFx 组件对象,并随时更新现有组件对象。另一个对您有用的重要概念 - 属性。属性(property)包含一段时间的值(value)。并且属性可以被绑定(bind) - 当一个属性的值自动传播到另一个绑定(bind)属性时。每个 javafx 组件(控件/布局)接口(interface)都基于属性使用。

Button b = new Button("Create new console");
b.setOnAction(new EventHandler<ActionEvent>(){
... action() {
new Stage(new Scene(new Group(new TextArea(DeploymentTaskController.actLogTArea.getText()))))).show();
}
});

您必须创建一种 HashMap ,而不是 DeploymentTaskController.actLogTArea 来决定选择哪个文本区域来添加新内容:

DeploymentTaskController.actLogTAreaHashMap.get(<some key, to determine text area>);

并在创建新文本区域时在其中添加新文本区域。

关于java - 如何从文本区域创建到其他阶段的超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16464428/

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