this is basic example I got for a GUI from a book called Java In Easy Steps, I implemented the code as per the example but the imagery does not appear. What do I need to do in order to make it appear, is because of the URL getClassLoader?
Ideally I would like to be able to save a file to my workspace and use that file as a part of the GUI.
import javax.swing.*;
class Buttons extends JFrame {
JPanel pnl = new JPanel();
ImageIcon tick = new ImageIcon("tickURL");
ImageIcon cross = new ImageIcon("crossURL");
JButton btn = new JButton("Click Me");
JButton tickBtn = new JButton(tick);
JButton crossBtn = new JButton("STOP", cross);
ClassLoader ldr = this.getClass().getClassLoader();
java.net.URL tickURL = ldr.getResource("tick.png");
java.net.URL crossURL = ldr.getResource("cross.png");
public Buttons(){
super("Swing Window");
setSize( 500, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
add(pnl);
setVisible(true);
pnl.add(btn);
pnl.add(tickBtn);
pnl.add(crossBtn);
}
public static void main(String[]Args){
Buttons gui = new Buttons();
}
}
As simple as that.