Ho un JFrame. In questo ho due contenitori cioè due JPanel. un pannello contiene un’immagine. altri detiene un JButton. Quindi questi due vengono aggiunti a JTabbedPane.
Il mio problema è nell’utilizzare un’immagine .gif l’immagine diventa statica come qualsiasi altra immagine normale .jpg. Qualcuno può aiutarmi con qualche altra idea?
Ecco il mio codice:
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 actionPerformsd(ActionEvent e) { // TODO Auto-generated method stub } }