0

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);
}
3
Contributors
2
Replies
10
Views
4 Years
Discussion Span
Last Post by mKorbel
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.