Search code examples
javamethodsjoptionpane

Inluce Method inside JOptionPane


i want to ask something about put a method inside of an JOptionPane.showMessageDialog.

here i have

public Double Result() { 
Double NilaiAkhir = (getNilaiUjianKe1() * 0.20) + (getNilaiUjianKe2() * 0.25) + (getNilaiUlanganKe1() * 0.20) + 
                            (getNilaiUlanganKe2() * 0.20) + (getNilaiTugas() * 0.15);
        return Result;
    }

then i want to put this Double Result() inside of JOptionPane

    JOptionPane.showMessageDialog(
        Student.Result()
    );

but it doesn't allow me to do that, how do i include such a method inside JOptionPane ?


Solution

  • You can

    JOptionPane.showMessageDialog(frame, Double.toString(Student.Result()));
    

    And you can't just return Result in your snippet 1,

    but you can return NilaiAkhir, if that's what you wanted to do.