1个回答
展开全部
先建个JPanel子类用作加载图片
class mypanel extends JPanel
{
private ImageIcon imageicon;
public mypanel()
{
imageicon=new ImageIcon("pic.gif");
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
imageicon.paintIcon(this, g, 0, 0);
}
public Dimension getPreferredSize()
{
return new Dimension(imageicon.getIconWidth(),imageicon.getIconHeight());
}
}
在button的actionperformed()事件中
public void actionPerformed(ActionEvent event){
mypanel panel=new mypanel();
JPanel jpanel=new JPanel();
jpanel.add(panel,BorderLayout.NORTH);
JOptionPane.showMessageDialog(null,jpanel,"加载",JOptionPane.INFORMATION_MESSAGE);
}
就可以了
class mypanel extends JPanel
{
private ImageIcon imageicon;
public mypanel()
{
imageicon=new ImageIcon("pic.gif");
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
imageicon.paintIcon(this, g, 0, 0);
}
public Dimension getPreferredSize()
{
return new Dimension(imageicon.getIconWidth(),imageicon.getIconHeight());
}
}
在button的actionperformed()事件中
public void actionPerformed(ActionEvent event){
mypanel panel=new mypanel();
JPanel jpanel=new JPanel();
jpanel.add(panel,BorderLayout.NORTH);
JOptionPane.showMessageDialog(null,jpanel,"加载",JOptionPane.INFORMATION_MESSAGE);
}
就可以了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询