G
Guest
Gast
hallo,
ich bin nicht klar über Interface .Das Programm ist mit Interface.
Wie hätte das Programm ohne Interface realisiert werden können?
Danke!
ich bin nicht klar über Interface .Das Programm ist mit Interface.
Wie hätte das Programm ohne Interface realisiert werden können?
Danke!
Code:
import java.awt.*;
interface Draw{
public void doit(Graphics g,int x,int y);
}
public class What extends Frame{
Draw m_Draw;
public What(Draw d){
m_Draw=d;
setSize(300,200);
setVisible(true);
}
public void paint(Graphics g){
for(int i=0;i<getWidth();i+=5)
for(int j=0;j<getHeight();j+=5)
m_Draw.doit(g,i,j);
}
public static void main(String[]args){
new What(new Draw(){
public void doit(Graphics g,int x,int y){
g.drawOval(x,y,5,5);
}
});
new What(new Draw(){
public void doit(Graphics g,int x,int y){
g.drawLine(x,y,x+5,y+5);
}
});
}
}