Add Images into the Java Interfaces Using jpl_new or jpl_call

141 views
Skip to first unread message

Ting Tze Sheng

unread,
Apr 29, 2018, 3:07:28 AM4/29/18
to swi-p...@googlegroups.com
Hi, I was developing an expert system in swi prolog with java interface, the main problem is that i don't know how to insert images into the interfaces, I have tried by converting the java code into the prolog with jpl, it shows no error, but the panel does not show the image.

interface:-
        jpl_new('javax.swing.JFrame', ['Expert System'], F),
jpl_new('javax.swing.JPanel',[],Pan),
jpl_new('javax.swing.JLabel',[],LBL),
jpl_new('javax.swing.ImageIcon', ['C:/Users/Ryan/Deskstop/cat.png'], Pic),
jpl_call(LBL, setIcon, [Pic], _),
jpl_call(Pan,add,[LBL],_),
jpl_call(F,add,[Pan],_),
jpl_call(F, setLocation, [400,300], _),
jpl_call(F, setSize, [400,300], _),
jpl_call(F, setVisible, [@(true)], _),
jpl_call(F, toFront, [], _).

which is equivalent in java code such as:

  JLabel lblwelcomeToExpert = new JLabel("====Welcome to Expert System====");
lblwelcomeToExpert.setBounds(95, 13, 232, 81);
icon = new ImageIcon("C:/Users/Ryan/Desktop/cat.png");
lblwelcomeToExpert.setIcon(icon);
panel.add(lblwelcomeToExpert);

I have tried alternative with by calling JOptionPane.showInputDialog in prolog(same piece of code on above):

         jpl_call('javax.swing.JOptionPane', showInputDialog, [F,'Hi. How are you? First of all tell me your name please','Expert System', 'INFORMATION_MESSAGE', Pic, null,''], N),

which should be the same as:
JOptionPane.showInputDialog(frame, "input for testing","hello", JOptionPane.INFORMATION_MESSAGE, icon, null, "");

Please show me the correct syntax, i've searched on google but there is no good examples for me to refer. Sorry for the bad English, not my primary language.
Reply all
Reply to author
Forward
0 new messages