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?
Obrigado,
Olá amigo!
Começe por aqui:
//circulos animados
import java.awt.*;
import BreezyGUI.*;
public class animatedcircle extends GBFrame
{
public void paint(Graphics g)
{
int x = 50, y = 50, width = 50, height = 50; // we are using a circle
int i;
for (i = 1; i <= 10; i++)
{
// draw the circle in red
g.setColor(Color.red);
g.drawOval(x, y, height, width);
pause(200);
// draw the circle in white to erase
if (i == 10)
g.setColor(Color.red); // leaves a red circle when done
else
g.setColor(Color.white);
g.drawOval(x, y, height, width);
//make adjustments to move the circle
width = (int) (width*1.25);
height = (int) (height*1.25);
}
Font ArialB16 = new Font("Arial", Font.BOLD, 16);
g.setColor(Color.red);
g.setFont(ArialB16);
g.drawString("Java Moves!!!", 180, 240);
}
//Main
public static void main (String[] args)
{
Frame frm = new animatedcircle();
frm.setSize (440,440);
frm.setVisible(true);
}
//Method to pause
public static void pause (int time)
{
try
{
Thread.sleep(time);
}
catch(InterruptedException e)
{
}
}
}
tem mais esse:
Gira pelo raio(utilizando aquela formulinha da escola) hehehe
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
/** An applet that displays a simple animation */
public class BouncingCircle extends Applet implements Runnable {
int x = 150, y = 50, r = 50; // Position and radius of the circle
int dx = 11, dy = 7; // Trajectory of circle
Thread animator; // The thread that performs the animation
volatile boolean pleaseStop; // A flag to ask the thread to stop
/** This method simply draws the circle at its current position */
public void paint(Graphics g) {
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.
*/
public void animate() {
// Bounce if weve hit an edge.
Rectangle bounds = 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.
*/
public void run() {
while (!pleaseStop) { // Loop until were asked to stop
animate(); // Update and request redraw
try {
Thread.sleep(100);
} // Wait 100 milliseconds
catch (InterruptedException e) {
} // Ignore interruptions
}
}
/** Start animating when the browser starts the applet */
public void start() {
animator = new Thread(this); // Create a thread
pleaseStop = false; // Dont ask it to stop now
animator.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 */
public void stop() {
// Set the flag that causes the run() method to end
pleaseStop = true;
}
}
Um grande abraço!
Eu fiz usando JLabel com threads separadas. Ficou show! Usamos para sortear prêmios mensais.
Obrigado pela dica pessoal!
assim que eu tiver uma chance eu posto aqui o resultado rs!
obrigado