我想显示一个显示字符串值的消息窗口,但我不知道如何编写它。我有这段代码:
for (BufferedImage bImage : lineImage1) {
int trafficSection[] = analysis.colorShare(screenCapturing.getMapTrafficOnly(), bImage);
String trafficString = trafficSection[0] + " - " + trafficSection[1] + " - " + trafficSection[2] + " - " + trafficSection[3];
JOptionPane.showMessageDialog(this, trafficString, JOptionPane.INFORMATION_MESSAGE);
}
但它不起作用。任何人都可以帮我,请问如何为消息窗口编写代码?
由于
这是错误:
java: no suitable method found for showMessageDialog(<anonymous cege.controller.ScreenCaptureController.ScreenCaptureListener>,java.lang.String,java.lang.String,int)
method javax.swing.JOptionPane.showMessageDialog(java.awt.Component,java.lang.Object,java.lang.String,int,javax.swing.Icon) is not applicable
(actual and formal argument lists differ in length)
method javax.swing.JOptionPane.showMessageDialog(java.awt.Component,java.lang.Object,java.lang.String,int) is not applicable
(actual argument <anonymous cege.controller.ScreenCaptureController.ScreenCaptureListener> cannot be converted to java.awt.Component by method invocation conversion)
method javax.swing.JOptionPane.showMessageDialog(java.awt.Component,java.lang.Object) is not applicable
(actual and formal argument lists differ in length)
我解决了。我刚才把这个名字放在了这个名字之前。
答案 0 :(得分:0)
JOptionPane.showMessageDialog(null, "write msg here", "Title msg", JOptionPane.WARNING_MESSAGE);
这是警告信息。如果您想要其他类型,只需将WARNING_MESSAGE更改为其他类型(可能需要更多或更少的参数)。 http://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html
答案 1 :(得分:0)
我可能错了,但我怀疑您的lineImage1
数组可能为空,导致JOptionPane
来电无法访问。
选项窗格代码似乎很好。尝试使用虚拟字符串在循环外测试它。
祝你好运。