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

时间:2013-05-09 14:38:54

标签: java javafx-2

在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();

1 个答案:

答案 0 :(得分:1)

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

怎么做:

  1. 创建一个按钮(超链接,如果需要)
  2. setOnAction(new EventHandler<ActionEvent>(){})并将下一个代码添加到函数中:
  3. new Stage(new Scene(new Group(new TextArea(ta.textProperty().bind(ta.textProperty()))))).show(),其中ta - 是您第一阶段的文字区域。
  4. 您必须注意,JavaFX是一种面向对象的GUI技术,您可以随时创建新的javaFx组件对象,并在您拥有访问权限或链接时随时更新现有的javaFx组件对象。另一个重要的概念,对你有用 - 属性。属性包含一段时间的值。属性可以绑定 - 当一个属性的值自动传播到另一个绑定属性时。每个javafx组件(控件/布局)接口都基于属性用法。

    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();
        }
    });
    

    您必须创建一种哈希映射来决定选择添加新内容的文本区域,而不是DeploymentTaskController.actLogTArea:

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

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