I am worked in project that I have to do simulator to traffi

I am worked in project that I have to do simulator to traffic air control using Java language to avoid collisions .

how can i make the two object moving in the frame according to input values of coordinate ?
I am worked in project that I have to do simulator to traffic air control using Java language to avoid collisions .

how can i make the two object moving in the frame according to input values of coordinate ?

how can i make the two object moving in the frame according to input values of coordinate ?

Solution

You can use swing for this purpose, since I don\'t have much description of your project I am going to share my sample code of a project on which I worked long time back then. Try to run it and understand the concept may be that can help in your project. By the way this project which I am going to share is a code of bouncy balls objects moving.

In this project swingBot is used for moving the object. I hope this will help you in your project.

import java.awt.Graphics;
import javax.swing.JComponent;
import java.awt.Rectangle;
import java.util.Scanner;
import java.awt.event.ActionListener;
import java.awt.Graphics2D;

import java.awt.geom.Line2D;
import java.awt.geom.Ellipse2D;
import javax.swing.JFrame;
import javax.swing.Timer;
import java.awt.Color;
import java.awt.Polygon;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;

import java.util.Random;

public class Original {

    public static void main(String[] args) {   

        // New jFrame object is constructed here

        JFrame frame = new JFrame();   

        // mutators

        frame.setSize(400,400);

        frame.setTitle(\"SwingBot\");   

        // When the window closes, program will end

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   

        Robot r = new Robot();

        frame.add(r);

        // voila!

        frame.setVisible(true);

        // Scanner code loop       

        int noend = 0;

        System.out.println(\"input your command:\");

        while(noend == 0)

        {

             Scanner input = new Scanner(System.in);

             String command = input.next();

             if(command.equals(\"left\"))

                 r.moveBot(-10,0);

             if(command.equals(\"right\"))

                 r.moveBot(10,0);

             if(command.equals(\"down\"))

                 r.moveBot(0,10);

             if(command.equals(\"up\"))

                 r.moveBot(0,-10);

        }           

        // call methods on the Robot instance like

//w.moveBot(10,10) in response to input of the user

       

    }   

    public static class Robot extends JComponent

    {

        private Rectangle rect = new Rectangle(20,60);

        private Polygon poly = new Polygon();

        public void paintComponent(Graphics g)

        {

            Graphics2D g2 = (Graphics2D) g;              

            // set the color

            g2.setColor(Color.ORANGE);               

            // draw the shape`

            g2.fill(rect);               

            int xPoly[] = {75, 125, 170, 170, 200, 105, 60};

            int yPoly[] = {75, 50, 88, 111, 125, 180, 150};   

            poly = new Polygon(xPoly, yPoly, xPoly.length);

                super.paintComponent(g);

                g.setColor(Color.BLUE);

                g.drawPolygon(poly);               

        }

        public void moveBot(int x, int y)

        {

            // move the rectangle

            rect.translate(x,y);

            poly.translate(x,y);

            // redraw the window

            repaint();

        }           

    }

}

I am worked in project that I have to do simulator to traffic air control using Java language to avoid collisions . how can i make the two object moving in the
I am worked in project that I have to do simulator to traffic air control using Java language to avoid collisions . how can i make the two object moving in the
I am worked in project that I have to do simulator to traffic air control using Java language to avoid collisions . how can i make the two object moving in the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site