Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Swing中使用HTML代码_Java_Html_Swing_Joptionpane - Fatal编程技术网

Java 在Swing中使用HTML代码

Java 在Swing中使用HTML代码,java,html,swing,joptionpane,Java,Html,Swing,Joptionpane,我不知道如何在HTML中使用变量,在这种情况下字符串是一个变量 JOptionPane.showMessageDialog(null,"<html>Error #1<br> + string +</html>","Error",JOptionPane.PLAIN_MESSAGE); JOptionPane.showMessageDialog(空,“错误1+string+”,“错误”,JOptionPane.PLAIN\u消息); 此输出:错误#1+字符串

我不知道如何在HTML中使用变量,在这种情况下字符串是一个变量

JOptionPane.showMessageDialog(null,"<html>Error #1<br> + string +</html>","Error",JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(空,“错误1
+string+”,“错误”,JOptionPane.PLAIN\u消息);
此输出:错误#1+字符串

JOptionPane.showMessageDialog(null,"<html>Error #1<br></html>" + string ,"Error",JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(空,“错误1
”+字符串,“错误”,JOptionPane.PLAIN\u消息);
此输出:错误#1


有没有一种方法可以在HTML中使用字符串变量?

是否需要类似的内容

"<html>Error #1<br>" + string + "</html>"
“错误1”
“+string+”
??
如果要将
字符串
变量连接到html,它必须在引号之外,否则它将被视为文本,如您的示例所示。

是否需要类似的内容

"<html>Error #1<br>" + string + "</html>"
JOptionPane.showMessageDialog(
    null,
    "<html>Error #1<br>" + string + "</html>",
    "Error",
    JOptionPane.PLAIN_MESSAGE);
“错误1”
“+string+”
?? 如果要将
字符串
变量连接到html,它必须在引号之外,否则将被视为文本,如您的示例所示。

JOptionPane.showMessageDialog(
JOptionPane.showMessageDialog(
    null,
    "<html>Error #1<br>" + string + "</html>",
    "Error",
    JOptionPane.PLAIN_MESSAGE);
无效的 “错误#1
”+字符串+“”, “错误”, JOptionPane.普通消息);
尽管如此,请注意逻辑上的
JOptionPane.PLAIN\u消息应为
JOptionPane.ERROR\u消息

JOptionPane.showMessageDialog(
无效的
“错误#1
”+字符串+“”, “错误”, JOptionPane.普通消息);
但是请注意,逻辑上
JOptionPane.PLAIN\u MESSAGE
应该是
JOptionPane.ERROR\u MESSAGE
,您需要执行以下操作:
“ERROR”1
“+string+”

java中的字符串文字由零个或多个字符组成,这些字符用双引号括起来。所以任何满足这个条件的东西也将被视为字符串。在追加
字符串之前,需要先关闭该字符串

因此,如果
string=“Hi to stack”

然后,
“Error”1
“+string+”
将导致:

"<html>Error #1<br>Hi to stack</html>"
“错误#1
堆栈高”
您需要执行:
错误1
“+string+”

java中的字符串文字由零个或多个字符组成,这些字符用双引号括起来。所以任何满足这个条件的东西也将被视为字符串。在追加
字符串之前,需要先关闭该字符串

因此,如果
string=“Hi to stack”

然后,
“Error”1
“+string+”
将导致:

"<html>Error #1<br>Hi to stack</html>"
“错误#1
堆栈高”
JOptionPane.showMessageDialog(null,“Error#1
“+string+”,“Error”,JOptionPane.showMessageDialog(null,“Error#1
“+string+”,“Error”,