Ajuda com criação de uma interface gráfica simulando uma roleta
3 respostas
T
Tipertuba
Olá Pessoal,
Eu preciso de fazer um aplicativo que basicamente vai simular uma roleta. Meio parecido com essas roletas de prêmios desses programas de TV… ahahah
A ideia era que tivesse uma roleta com alguns prêmios a serem sorteados e que eu pudesse definir a probabilidade dos prêmios e etc.
O problema é que nunca mexi com gráficos nesse estilo. Sempre usei interface do próprio Netbeans…
Alguém pode me dar uma dica de como posso desenvolver isso ou algo já desenvolvido?
//circulos animadosimportjava.awt.*;importBreezyGUI.*;publicclassanimatedcircleextendsGBFrame{publicvoidpaint(Graphicsg){intx=50,y=50,width=50,height=50;// we are using a circleinti;for(i=1;i<=10;i++){// draw the circle in redg.setColor(Color.red);g.drawOval(x,y,height,width);pause(200);// draw the circle in white to eraseif(i==10)g.setColor(Color.red);// leaves a red circle when doneelseg.setColor(Color.white);g.drawOval(x,y,height,width);//make adjustments to move the circlewidth=(int)(width*1.25);height=(int)(height*1.25);}FontArialB16=newFont("Arial",Font.BOLD,16);g.setColor(Color.red);g.setFont(ArialB16);g.drawString("Java Moves!!!",180,240);}//Mainpublicstaticvoidmain(String[]args){Framefrm=newanimatedcircle();frm.setSize(440,440);frm.setVisible(true);}//Method to pausepublicstaticvoidpause(inttime){try{Thread.sleep(time);}catch(InterruptedExceptione){}}}
tem mais esse:
Gira pelo raio(utilizando aquela formulinha da escola) hehehe
importjava.applet.Applet;importjava.awt.Color;importjava.awt.Graphics;importjava.awt.Rectangle;/** An applet that displays a simple animation */publicclassBouncingCircleextendsAppletimplementsRunnable{intx=150,y=50,r=50;// Position and radius of the circleintdx=11,dy=7;// Trajectory of circleThreadanimator;// The thread that performs the animationvolatilebooleanpleaseStop;// A flag to ask the thread to stop/** This method simply draws the circle at its current position */publicvoidpaint(Graphicsg){g.setColor(Color.red);g.fillOval(x-r,y-r,r*2,r*2);}/** * This method moves (and bounces) the circle and then requests a redraw. * The animator thread calls this method periodically. */publicvoidanimate(){// Bounce if weve hit an edge.Rectanglebounds=getBounds();if((x-r+dx<0)||(x+r+dx>bounds.width))dx=-dx;if((y-r+dy<0)||(y+r+dy>bounds.height))dy=-dy;// Move the circle.x+=dx;y+=dy;// Ask the browser to call our paint() method to draw the circle// at its new position.repaint();}/** * This method is from the Runnable interface. It is the body of the thread * that performs the animation. The thread itself is created and started in * the start() method. */publicvoidrun(){while(!pleaseStop){// Loop until were asked to stopanimate();// Update and request redrawtry{Thread.sleep(100);}// Wait 100 millisecondscatch(InterruptedExceptione){}// Ignore interruptions}}/** Start animating when the browser starts the applet */publicvoidstart(){animator=newThread(this);// Create a threadpleaseStop=false;// Dont ask it to stop nowanimator.start();// Start the thread.// The thread that called start now returns to its caller.// Meanwhile, the new animator thread has called the run() method}/** Stop animating when the browser stops the applet */publicvoidstop(){// Set the flag that causes the run() method to endpleaseStop=true;}}
Um grande abraço!
F
FernandoFranzini
Eu fiz usando JLabel com threads separadas. Ficou show! Usamos para sortear prêmios mensais.
T
Tipertuba
Obrigado pela dica pessoal!
assim que eu tiver uma chance eu posto aqui o resultado rs!
obrigado