我正在努力在当前的Jframe上绘制一条线或点。
我已经生成了它,现在我想绘制它,而不会丢失帧数据。 我已经完成了一些建议,但大多数都建议重新绘制Jframe。其中一些人建议使用Jpanel。问题是我是新来的,我不认为我现在没有任何帮助。所以任何人都可以帮我这个..?
示例代码如下所示
private static JFrame showImage(BufferedImage src){
ImageIcon icon = new ImageIcon(img);
JLabel lbl = new JLabel();
lbl.setIcon(icon);
JFrame frame = new JFrame("JFrame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(lbl, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
return frame;
}
public static void main(String[] args) {
try {
//read image
try{
File f = new File("/home/amit/workspacenew/autocrop/screenshot_full_solid.png");
img = ImageIO.read(f);
}catch(IOException e){
System.out.println(e);
}
JFrame frame = showImage(img);
frame.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
int x=e.getX();
int y=e.getY();
//need suggestion here
drawdot(x, y);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}