import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FillJPanel extends JFrame
{
   public FillJPanel()
   {
       setSize(600,400);
       
       NewPanel p=new NewPanel();
       p.setLayout(new FlowLayout());
       JButton btt=new JButton("button");
              
       getContentPane().add(p,BorderLayout.CENTER);
       getContentPane().add(btt,BorderLayout.SOUTH);
       
       p.add(new JTextField(10));
       p.add(new JButton("   "));
       p.add(new JComboBox());
       
       addWindowListener(new WindowAdapter()
       {
        public void windowClosing(WindowEvent e)
        {
        System.exit(0);
        }
       });
       
       
   }
   public static void main(String arg[])
   {new FillJPanel().show();}
}class NewPanel extends JPanel
{    
   public NewPanel(){}
   public void paintComponent(Graphics g)
   {
       int x=0,y=0;
       java.net.URL imgURL = getClass().getResource("images\\photo.gif");         
       ImageIcon icon = new ImageIcon(imgURL);                     
       
       while(true)
       {   
           g.drawImage(icon.getImage(),x,y,Color.red,this);            
           if(x>getSize().width && y>getSize().height)break;            
           if(x>getSize().width){
               x=0;                
               y+=icon.getIconHeight();
           }
           else x+=icon.getIconWidth();
       }
     
   }   

解决方案 »

  1.   

    不好意思,刚才看错了.
    Toolkit tk = Toolkit.getDefaultToolkit();        
    Image im = tk.getImage("images\\photo.jpg"); 


    int w = im.getWidth( this );
    int h = im.getHeight( this );
      

  2.   

    不要方法,用属性
    .width()和.height()
      

  3.   

    .getWidth( )
    .getHeight( )
      

  4.   

    int w = im.getWidth( this );
    int h = im.getHeight( this );"this" 在这儿是指的什么?
      

  5.   

    在applet中时 image可以加到applet
    因为applet本身就可以做observer
      

  6.   

    应该是image.getHeigth(充当observer的对象);
      

  7.   

    observer对象哪儿来?
    能给个例子吗?
      

  8.   

    你看看observer是怎么用的,或者那些可以充当observer