thread problems
As it could solve this type of problems the program runs well but I would like to know how to fix those warnings
================================================================================================= ========================
import java.awt.geom.*;
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class UsoThreads {
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame marco=new MarcoRebote();
marco.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
marco.setVisible(true);
}
}
class PelotaHilos implements Runnable{
public PelotaHilos(Pelota unaPelota,Component unComponent){
pelota=unaPelota;
componente=unComponent;
}
@Override
public void run(){
for (int i=1; i<=3000; i++){
pelota.mueve_pelota(componente.getBounds());
componente.paint(componente.getGraphics());
try{
Thread.sleep(4);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
private Pelota pelota;
private Component componente;
}
//Movimiento de la pelota-----------------------------------------------------------------------------------------
class Pelota{
// Mueve la pelota invirtiendo posicion si choca con limites
public void mueve_pelota(Rectangle2D limites){
x+=dx;
y+=dy;
if(x<limites.getMinX()){
x=limites.getMinX();
dx=-dx;
}
if(x + TAMX>=limites.getMaxX()){
x=limites.getMaxX() - TAMX;
dx=-dx;
}
if(y<limites.getMinY()){
y=limites.getMinY();
dy=-dy;
}
if(y + TAMY>=limites.getMaxY()){
y=limites.getMaxY()-TAMY;
dy=-dy;
}
}
//Forma de la pelota en su posicion inicial
public Ellipse2D getShape(){
return new Ellipse2D.Double(x,y,TAMX,TAMY);
}
private static final int TAMX=15;
private static final int TAMY=15;
private double x=0;
private double y=0;
private double dx=1;
private double dy=1;
}
// Lamina que dibuja las pelotas----------------------------------------------------------------------
class LaminaPelota extends JPanel{
//Anadimos pelota a la lamina
public void add(Pelota b){
pelotas.add(b);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g;
for(Pelota b: pelotas){
g2.fill(b.getShape());
}
}
private ArrayList<Pelota> pelotas=new ArrayList<Pelota>();
}
//Marco con lamina y botones------------------------------------------------------------------------------
class MarcoRebote extends JFrame{
private Thread t;
public MarcoRebote(){
setBounds(600,300,400,350);
setTitle ("Rebotes");
lamina=new LaminaPelota();
add(lamina, BorderLayout.CENTER);
JPanel laminaBotones=new JPanel();
ponerBoton(laminaBotones, "Dale!", new ActionListener(){
public void actionPerformed(ActionEvent evento){
comienza_el_juego();
}
});
ponerBoton(laminaBotones,"suspender",new ActionListener(){
public void actionPerformed(ActionEvent evento){
t.suspend();
}
});
ponerBoton(laminaBotones,"reanudar",new ActionListener(){
public void actionPerformed(ActionEvent evento){
t.resume();
}
});
ponerBoton(laminaBotones, "Salir", new ActionListener(){
public void actionPerformed(ActionEvent evento){
System.exit(0);
}
});
add(laminaBotones, BorderLayout.SOUTH);
}
//Ponemos botones
public void ponerBoton(Container c, String titulo, ActionListener oyente){
JButton boton=new JButton(titulo);
c.add(boton);
boton.addActionListener(oyente);
}
//Anade pelota y la bota 1000 veces
public void comienza_el_juego (){
Pelota pelota=new Pelota();
lamina.add(pelota);
Runnable r=new PelotaHilos(pelota,lamina);
//Thread t=new Thread(r);
t=new Thread(r);
t.start();
}
private LaminaPelota lamina;
}
javac UsoThreads.java -Xlint:deprecation && java UsoThreads && rm *.class
UsoThreads.java:101: warning: [deprecation] suspend() in Thread has been deprecated
t.suspend();
^
UsoThreads.java:106: warning: [deprecation] resume() in Thread has been deprecated
t.resume();
^
2 warnings