L
LittleWulf
Gast
???:L
Hallo kann mir jemand sagen warum des net läuft. Und hat einer ne ahnung wie der timer befehl in eclipse funktioniert und was ich importieren muss?
DAnke mfg LittleWulf
Roar: Codetags!!
Hallo kann mir jemand sagen warum des net läuft. Und hat einer ne ahnung wie der timer befehl in eclipse funktioniert und was ich importieren muss?
Code:
package Anfang;
import java.awt.*;
import java.awt.event.*;
public class Bild extends Frame implements ActionListener {
Button bt1, bt2;
Canvas cv;
public Bild (){
setLayout (new BorderLayout());
cv = new Canvas();
cv.setBounds(10,10,600,400);
cv.setBackground(Color.yellow);
add (cv,"Center");
bt1 = new Button ("Start");
add (bt1,"North");
bt1.addActionListener (this);
bt2 = new Button ("Stop");
add (bt2,"South");
bt2.addActionListener (this);
initComponenets ();
}
private void initComponenets ()
{
addWindowListener (new WindowAdapter (){
public void windowClosing (WindowEvent ev){
exitForm(ev);}});
pack ();}
private void exitForm (WindowEvent ev) {
System.exit(0);}
public void maleKreis(int xm,int ym){
Graphics g = cv.getGraphics();
g.setColor(Color.red);
int r=30;
g.fillOval(xm-r,ym-r,2*r,2*r);
g.dispose();}
public void loescheKreis(int xm,int ym){
Graphics g = cv.getGraphics();
g.setColor(Color.yellow);
int r=30;
g.fillOval(xm-r,ym-r,2*r,2*r);
g.dispose();}
public void actionPerformed(ActionEvent e){
boolean start = false;
int x = 100; int vx = 5;
int y = 150; int vy = 4;
if(e.getSource()==bt1) start = true;
if(e.getSource()==bt2) start = false;
while(start = true){
int n =1;
n++;
maleKreis(x,y);
for(int i=1;i<10000;i++){
for(int j =1;j<500;j++);}
loescheKreis(x,y);
x=x+vx;
y=y+vy;
if(y>370||y<130)vy=-vy;
if(x>570||x<130)vx=-vx;
if(n>1000) start = false;
}
}
public static void main(String[] args) {
Bild toll = new Bild ();
toll.setBackground (Color.red);
toll.setLocation (300,300);
toll.setSize (700,500);
toll.show ();
}
}
DAnke mfg LittleWulf
Roar: Codetags!!