Original Post
Can u plz have a look @ this code and tell me where the problem is can it aint loading the internal frame pricture up atm
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DesktopTest extends JFrame {
public DesktopTest()
{
super( "Using a Desktop" );
JMenuBar bar = new JMenuBar( );
JMenu addMenu = new JMenu( "Add" );
JMenuItem newFrame = new JMenuItem( "Internal Frame");
addMenu.add( newFrame );
bar.add( addMenu );
setJMenuBar( bar );
final JDesktopPane theDesktop = new JDesktopPane( );
getContentPane( ).add( theDesktop );
newFrame.addActionListener(
new ActionListener( ){
public void actionPerformed( ActionEvent e )
{
JInternalFrame frame =
new JInternalFrame( "Internal Frame" , true, true, true, true );
Container c = frame.getContentPane( );
MyJPanel panel = new MyJPanel( );
c.add( panel , BorderLayout.CENTER );
frame.setSize(
panel.getImageWidthHeight().width,
panel.getImageWidthHeight( ).height );
frame.setOpaque( true );
theDesktop.add( frame );
}
}
);
setSize( 640, 480 );
show( );
}
public static void main( String args[ ] )
{
DesktopTest app = new DesktopTest();
app.addWindowListener(
new WindowAdapter( ){
public void windowClosing( WindowEvent e )
{
System.exit( 0);
}
}
);
}
public class MyJPanel extends JPanel{
private ImageIcon imgIcon;
public MyJPanel( )
{
imgIcon = new ImageIcon( "E:\\Java\\bug.gif" );
}
public void paintComponent( Graphics g )
{
imgIcon.paintIcon( this , g , 0 , 0 );
}
public Dimension getImageWidthHeight( )
{
return new Dimension( imgIcon.getIconWidth(), imgIcon.getIconHeight() );
}
}
}
thxs