简体   繁体   English

如何从JOptionPane.showMessageDialog中读取

[英]How to read from a JOptionPane.showMessageDialog

I'm trying to get the location from a mouse click.I have the following code: 我试图通过单击鼠标获取位置。我有以下代码:

import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class test {
public static void main(String[] args) {
    final Browser browser = new Browser();
    BrowserView view = new BrowserView(browser);

    final JTextField addressBar = new JTextField(
            "https://developer.here.com/api-explorer/maps-js/v3.0/infoBubbles/position-on-mouse-click");
    addressBar.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            browser.loadURL(addressBar.getText());
        }
    });

    JPanel addressPane = new JPanel(new BorderLayout());
    addressPane.add(new JLabel(" URL: "), BorderLayout.WEST);
    addressPane.add(addressBar, BorderLayout.CENTER);

    JFrame frame = new JFrame("Website");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.add(addressPane, BorderLayout.NORTH);
    frame.add(view, BorderLayout.CENTER);
    frame.setBounds(1, 1, 1300, 700);
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    browser.loadURL(addressBar.getText());
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }
    }
    }

And when I click on that map from the website, I receive a messageBox with the coordinates. 当我从网站上单击该地图时,会收到带有坐标的messageBox。

My question is how to obtain these coordinates(numbers)? 我的问题是如何获取这些坐标(数字)?

I got that script from the website and created a hmtl file using it and a little javascript code the get,somehow the coordinates by writing them into a text file. 我从网站上获取了该脚本,并使用它创建了一个hmtl文件,并使用了一些javascript代码对get进行了编码,通过某种方式将坐标写入了文本文件中。

It didn't work and after that I realized that according to some ppl from the internet is impossible to write data in files using javascript(Being a security risk). 它没有用,然后我意识到根据互联网上的一些数据,不可能使用javascript在文件中写入数据(存在安全隐患)。

So after it,the javascript option is down.And now I wonder if is possible to somehow get these informations from the messageBox... I have to mention that I'm forced to code only with javascript and Java. 因此,在此之后,javascript选项关闭了。现在,我想知道是否有可能以某种方式从messageBox中获取这些信息...我不得不提一下,我被迫仅使用javascript和Java进行编码。 And I'm using JxBrowser to display the webpage in my Java Application and Swing for GUI. 而且我正在使用JxBrowser在Java应用程序和GUI的Swing中显示网页。

Calculating a Location from a Mouse Click is a site that provides you the location coordinates on click,the location being sent using an alertwindow(in javascript). 通过鼠标单击计算位置是一个网站,可为您提供单击时的位置坐标,该位置是使用警报窗口(在javascript中)发送的。 When I open this site in my Java app I don't receive the alertwindow (because I open it using Java and not a browser), I receive an JOptionPane.showMessageDialog . 当我在Java应用程序中打开此站点时,没有收到Alertwindow(因为我是使用Java而不是浏览器来打开它的),所以会收到JOptionPane.showMessageDialog

So what I want is to extract/get the coordinates from this JOptionPane . 所以我想要从这个JOptionPane提取/获取坐标。

The DialogHandler.onAlert() method is invoked when JavaScript alert dialog should be displayed. 当应该显示JavaScript警报对话框时,将调用DialogHandler.onAlert()方法。 It happens when the window.alert() JavaScript function is invoked. 调用window.alert()JavaScript函数时会发生这种情况。 that one is the equivalent you can manage alert by overriding the DialogHandler.onAlert() 那是等效的,您可以通过重写DialogHandler.onAlert()来管理警报

browser.setDialogHandler(new DialogHandler() {
    @Override
    public void onAlert(DialogParams params) {
        String url = params.getURL();
        String title = "The page at " + url + " says:";
        String message = params.getMessage();
        JOptionPane.showMessageDialog(null, message, title, JOptionPane.PLAIN_MESSAGE);
    }

for additional info check tutorial javascript dialog for JXBrowser here 有关其他信息,请在此处查看JXBrowser的JavaScript教程对话框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM