mohamedmaerouf
19-12-2009, 12:31
فى داله timer in java
انا عملت برنامج فيه عربيه بتتحرك بس لما بتوصل لنهايه الفرامه مش بتظهر بعد كده تمام انا عايزها لما تصل لنهايه الفرامه تبدأ تانى من الاول
وده الكود
//in the name off allah
import javax.swing.*;
import java.awt.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.*;
public class racecar extends JFrame {
public racecar() {
setTitle("BMW");
add(new draw ());
}
public static void main(String[] args) {
racecar frame = new racecar();
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setSize(400,250);
frame.setVisible(true);
}
}
// Draw in the panel
class draw extends JPanel {
int mohamed= 15 ;
Timer t = new Timer(90,new TimerClass());
protected void paintComponent(Graphics g){
t.start();
super.paintComponent(g);
g.fillOval(mohamed,190,10,10);
g.fillOval(mohamed+20,190,10,10);
g.setColor(Color.CYAN);
g.fillRect(mohamed-10,180,50,10);
g.setColor(Color.pink);
Polygon polygon = new Polygon();
int []x={mohamed ,mohamed+10,mohamed+20,mohamed+30};
int []y={180,170,170,180};
g.fillPolygon(x,y,x.length);
}
class TimerClass implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mohamed+= 20;
repaint();
}
}
}
انا عملت برنامج فيه عربيه بتتحرك بس لما بتوصل لنهايه الفرامه مش بتظهر بعد كده تمام انا عايزها لما تصل لنهايه الفرامه تبدأ تانى من الاول
وده الكود
//in the name off allah
import javax.swing.*;
import java.awt.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.*;
public class racecar extends JFrame {
public racecar() {
setTitle("BMW");
add(new draw ());
}
public static void main(String[] args) {
racecar frame = new racecar();
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setSize(400,250);
frame.setVisible(true);
}
}
// Draw in the panel
class draw extends JPanel {
int mohamed= 15 ;
Timer t = new Timer(90,new TimerClass());
protected void paintComponent(Graphics g){
t.start();
super.paintComponent(g);
g.fillOval(mohamed,190,10,10);
g.fillOval(mohamed+20,190,10,10);
g.setColor(Color.CYAN);
g.fillRect(mohamed-10,180,50,10);
g.setColor(Color.pink);
Polygon polygon = new Polygon();
int []x={mohamed ,mohamed+10,mohamed+20,mohamed+30};
int []y={180,170,170,180};
g.fillPolygon(x,y,x.length);
}
class TimerClass implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mohamed+= 20;
repaint();
}
}
}