Quadro Posted September 2, 2012 Share Posted September 2, 2012 (edited) O fereastra in care apar cercuri generate de program, cu marime, pozitie si culoare aleatorie, iar raza fiecarui cerc crescand cu 1pixel/50milisecunde. Download: http://www.mediafire...q0nuf4vlvo2o15o Screenshot: Sursa: ********************************************************************************************** import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.util.ArrayList; import java.util.Random; import javax.swing.JFrame; public class Inceput extends JFrame implements Runnable { Graphics backG; Image backImage; Thread thread = new Thread(this); class Cerc{ int x=100, y=100, radius=300; Random r = new Random(); Color color = new Color(r.nextInt(250), r.nextInt(250), r.nextInt(250)); ArrayList<Cerc> listaCercuri = new ArrayList<Cerc>(); public void createCerc(){ if(listaCercuri.size() < 100) listaCercuri.add(new Cerc()); else listaCercuri.clear(); } public Cerc(){ x=r.nextInt(800); y=r.nextInt(600); radius= (20+ r.nextInt(50)); } } Cerc cerc = new Cerc(); public static void main(String[] args){ Inceput t = new Inceput(); t.init(); } public void init(){ setTitle("Animation"); setSize(800, 600); setLocationRelativeTo(null); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); thread.start(); } public void update(Graphics g){ if(backImage == null){ backImage = createImage(800, 600); backG = backImage.getGraphics(); } for(int i=0; i < cerc.listaCercuri.size(); i++ ){ backG.fillOval(cerc.listaCercuri.get(i).x - cerc.listaCercuri.get(i).radius, cerc.listaCercuri.get(i).y - cerc.listaCercuri.get(i).radius, 2*cerc.listaCercuri.get(i).radius, 2*cerc.listaCercuri.get(i).radius); backG.setColor(cerc.listaCercuri.get(i).color); cerc.listaCercuri.get(i).radius++; } g.drawImage(backImage, 0, 0, this); } public void paint(Graphics g){ update(g); } public void run(){ while(true) { repaint(); cerc.createCerc(); try{ Thread.sleep(50); }catch(Exception e){ e.printStackTrace(); } } } } ********************************************************************************************** Edited June 11, 2017 by eB Teodor Link to comment Share on other sites More sharing options...
5061756C Posted September 20, 2012 Share Posted September 20, 2012 Chiar e dragut, am facut ceva asemanator in XNA acum o saptamana cand invatam pentru prima oara, era doar un cerc care se loveste de margini si creste viteza E foarte fain felicitari! Link to comment Share on other sites More sharing options...
Recommended Posts