I am trying to add actions and paint on the image in JPanel. Till now I could only succeed to add image into the JPanel. But I could not add mouse actions on the image and paint it. Can anyone please go through my code and give suggestions!!

public class LinePanel extends JPanel{
public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseDragged(MouseEvent e) {

    }
}


}

private void display() throws IOException{

    //code to get the image 


    JFrame frame = new JFrame("LinePanel");
    frame.setPreferredSize(new Dimension(800, 800));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel image = new JLabel(new ImageIcon(img));


JPanel panel = new JPanel();  
    JScrollPane jspane=new JScrollPane(panel); 

frame.add(jspane, BorderLayout.CENTER);
    panel.add(image);
    panel.add(this);




    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

Recommended Answers

All 2 Replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.