JAVAgif图像在添加到JTabed窗格时不会移动
我有一个JFrame。因为我有两个容器,即两个JPanel。一个面板上有一个图像。另一个拿着一个按钮。然后将这两个元素添加到JTabbedPane中
我的问题是如何使用一个。gif图像该图像与任何其他正常图像一样变为静态。jpg图像。谁能再帮我提些主意吗
这是我的密码:
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URL;
import java.net.UnknownHostException;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.UIManager.LookAndFeelInfo;
public class ICLOUD implements ActionListener {
private BufferedImage bg;
JButton b1;
private Object frame1;
JFrame frame2 = new JFrame();
JDesktopPane desktop = new JDesktopPane();
public ICLOUD() {
try {
URL url = this.getClass().getResource("anigif.gif");
bg = ImageIO.read(url);
} catch (IOException ex) {
}
JPanel tabPanel = new JPanel(new GridBagLayout()) {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(bg, 0, 0, getWidth(), getHeight(), this);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(400, 300);
}
};
JPanel buttons = new JPanel(new GridLayout(4, 1, 15, 15));
buttons.setOpaque(false);
ImageIcon icon5 = new ImageIcon(ICLOUD.class.getResource("hi.jpg"));
b1=new JButton("Hello");
buttons.add(b1);
tabPanel.add(buttons);
JTabbedPane tabPane = new JTabbedPane();
tabPane.addTab(null,icon5, tabPanel);
JFrame frame = new JFrame("I-CLOUD");
b1.setVisible(true);
frame.setContentPane(tabPane);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
public static void main(String[] args) {
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
}
ICLOUD r=new ICLOUD();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
# 1 楼答案
让我来演示一下你正在挖的洞
你可以
或者你可以
现在,这是非常不充分的,只是为了举例。它不支持处理方法或优化GIF。。。所以你可以开始想象做这项工作所需要的额外工作量。。。很多
如果你想填写,请看一下GIF Specifications