So I have a panel that has an BufferedImage in it, and I would like to draw a line over that image, overlapping it.
I have tried the following example that I found from google but it doesn't seem to work:
public class Main {
private JFrame frame = new JFrame();
private JLayeredPane lpane = new JLayeredPane();
private JPanel panel1 = new JPanel();
private JPanel panel2 = new JPanel();
public Main()
{
frame.setPreferredSize(new Dimension(600, 400));
frame.setLayout(new BorderLayout());
frame.add(lpane, BorderLayout.CENTER);
lpane.setBounds(0, 0, 600, 400);
panel1.add(image);
panel1.setBounds(0, 0, 600, 400);
panel1.setOpaque(true);
panel2.add(linedraw1);
panel2.setBounds(200, 100, 100, 100);
panel2.setOpaque(true);
lpane.add(panel1, new Integer(0), 0);
lpane.add(panel2, new Integer(1), 0);
frame.pack();
frame.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new Main();
}
}
The following code just shows a blank gui, I tried adding a separate panel to the frame but when I do that only the new panel shows and nothing else. Any ideas?
Thanks in advance.