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();
}
}
}
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();
}
}
}
Toolkit tk = Toolkit.getDefaultToolkit();
Image im = tk.getImage("images\\photo.jpg");
int w = im.getWidth( this );
int h = im.getHeight( this );
.width()和.height()
.getHeight( )
int h = im.getHeight( this );"this" 在这儿是指的什么?
因为applet本身就可以做observer
能给个例子吗?