有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何从jOptionPane在JFrame上显示输入?

所以我有这个代码

String input;
input = JOptionPane.showInputDialog("Type words:");

如果此代码位于我的mouseListener中,我如何在JFrame中显示输入

我没有使用System.out.println(),因为它只在控制台中打印


共 (1) 个答案

  1. # 1 楼答案

    this

    String input;
    input = JOptionPane.showInputDialog("Type words:");
    JOptionPane.showMessageDialog(null, input);
    

    如果您确实需要在新的JFrame上显示它,您可以创建一个新的JFrame并将input添加到JLabel

    JFrame frame = new JFrame("The Title");
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.setSize(100,100);
    frame.getContentPane().add(new JLabel(input));
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);