一个简单的方法就是点击以后创建一个JLabel 构造函数中使用ImageIcon
如 假设layout方式为null
Label image;frame_click(MouseEvent e)
{
……
image=new Label(new ImageIcon("picture.gif"));
image.setBounds(x,y,cx,cy);
frame.getContentPane().add(image);
}
如 假设layout方式为null
Label image;frame_click(MouseEvent e)
{
……
image=new Label(new ImageIcon("picture.gif"));
image.setBounds(x,y,cx,cy);
frame.getContentPane().add(image);
}
1、创建一JPanel实例,把它添加到JFrame中;
2、在创建的JPanel实例中重载paintComponent(Graphics2D g)方法,在方法中画图g.draw(yourPicture,x,y……),x和y从下面的步骤中取得;
3、监视鼠标的移动,当点击时得到鼠标的坐标x和y。
按照上面的思路,你可以做出!
"Frame1.java": Error #: 300 : constructor JLabel(java.lang.String, javax.swing.ImageIcon) not found in class javax.swing.JLabel
按照你的方法做也有类似的错误
not found in class java.awt.Graphics
请大家帮忙
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
BufferedImage tempimage = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
WritableRaster raster = tempimage.getRaster();
raster.setPixel(j, i, color);
g.drawImage(image,0,0, this);
}
如果你的图像格式是.jpg直接就可以显示。
Icon icon = new ImageIcon("ddd.gif");吧!
JLabel jb = new JLabel(icon);