0

I want to show a message window displaying a string value, but I don't know how to write it. I have this code:

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

but it doesn't work. Can anybody help me please how to write a code for the message window?

Thanks

Here is the error:

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)

I solved it. I just put the name of the class before this.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user3186565
  • 9
  • 1
  • 3

2 Answers2

0
JOptionPane.showMessageDialog(null, "write msg here", "Title msg", JOptionPane.WARNING_MESSAGE);

This is for warning message. If you want an other, just change WARNING_MESSAGE to another type (might take more or less params). http://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html

3751_Creator
  • 656
  • 2
  • 8
  • 22
0

I may be wrong but I doubt that your lineImage1 array might be empty, making your JOptionPane call unreachable.

The Option Pane code seems fine. Try testing it outside the loop using a dummy string.

Good luck.

Tanmay Patil
  • 6,882
  • 2
  • 25
  • 45