Results 1 to 2 of 2

Thread: ayuda (URGENTE)

  1. #1
    nacho is offline Member
    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Default ayuda (URGENTE)

    saludos amigos necesito q me ayuden urgente con este programa.. Necesito q me digan q es lo q hace por sectores

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class Coseno
    {
    public static void main(String[]args)
    {
    JFrame frame = new BounceFrame();
    frame.show();
    }
    }
    class BounceFrame extends JFrame
    {
    public BounceFrame()
    {
    setSize(300,200);
    setTitle("Bounce");
    addWindowListener(new WindowEvent e)
    {
    System.out(0);
    }

    });

    Container contentPane = getContentPane();
    canvas = new JPanel();
    contentPane.add(canvas, "Center");
    JPanel p= new JPanel();
    //Thread.currentThread().setPriority(Thread.currentT hread().MAX_PRIORITY);

    addButton(p,"Start",new ActionListener()
    {
    public void actionPerformed(ActionEvent evt)
    {
    Ball b= new Ball(canvas,Color.black);
    b.setPriority(Thread.MIN_PRIORITY/*NORM_PRIORITY*/);
    b.start();
    }
    });

    addButtonm(p,"Expres";newActionListener()
    {
    public void actionPreformed(ActionEvent evt)
    {
    Ball b= new Ball(canvas,Color.red);
    b.setPriority(Thread.MAX_PRIORITY/*NORM_PRIORITY+2*/);
    b.start();
    }
    });

    addButtonm(p,"Close";newActionListener()
    {
    public void actionPreformed(ActionEvent evt)
    {
    canvas.setVisible(false);
    System.exit(0);
    }
    });

    contentPane.add(p,"South");
    }
    public void addButton(Container c,String tilte, ActionListener a)
    {
    JButton b = new JButton(title);
    c.add(b);
    b.addActionListener(a);
    }


    private JPanel canvas;
    }
    class Ball extends Thread
    {
    public Ball (JPanel b,Color c)
    {
    box=b;
    color=c;
    }
    publica la pelota

    public void draw()
    {
    Graphics g=box.getGraphics();
    g.setColor(color);
    g.fillOval(x,y,XSIZE,YSIZE);
    g.dispose();
    }

    public void move()
    {
    if(!box.isVisible())return;
    Graphics g = box.getGraphics();
    get.setXORMode(box.getBackground());
    get.setColor(color);
    g.fillOval(x,y,XSIZE,YSIZE);
    x+=dx;
    y+=dy;
    Dimension d=box.getSize();
    if(x<0)
    {
    x=0;
    dx=-dx;
    }
    if(x+XSIZE>=d.width)
    {
    x=d.width-XSIZE;dx=-dx;
    }
    if(y<0)
    {
    y=0;
    y=-dy;
    }
    if(y+YSIZE>=d.height)
    {
    y=d.height-YSIZE;
    dy=-dy;
    }
    g.fillOval(x,y,XSIZE,YSIZE);
    //(g.dispose();
    }

    public void run()
    {
    try
    {
    draw();
    for(int i=1;i<=10000;i++)
    {
    move();
    sleep(1);
    }
    }
    catch(InterruptedExeption e){}
    }

    private JPanel box;
    private static final int XSIZE=10;
    private static final int YSIZE=10;
    private int x=0;
    private int y=0;
    private int dx=2;
    private int dy=2;
    private Color color;
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •