Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A. Write a JAVA program to create the following frame: B. Add the following acti

ID: 3766588 • Letter: A

Question

A. Write a JAVA program to create the following frame:

B. Add the following actions to your car component as the following:

When the user clicks the right mouse button the car will start moving horizontally to the right.

When the user clicks the left mouse button the car should move horizontally to the left.

You need to use an instance of the Timer class to animate the car component.

Hints:

To check whether you clicked the right button use event.getButton() == MouseEvent.BUTTON1

To check whether you clicked the left button use event.getButton() == MouseEvent.BUTTON3

Add a toolTip text to the car component using the setToolTipText("Clink on to move") method.

Set the frame size to width = 400 and Height = 100.

Use the following dimensions for your car shape component x = 20, y = 20, width = 80

Move the car

Explanation / Answer

a)
public void run()
{
Thread t1=Thread.currentThread();
while(t==t1)
{
   repaint();
   try
   {
    Thread.sleep(100);
   }
   catch(Exception e)
   {   }
}
}
public void paint(Graphics g)
{
setBackground(Color.cyan);
g.setColor(Color.BLACK);
x1=(x1+16)%400;
x2=x2-16;
y1=(y1+12)%300;
y2=y2-12;
if(y2<0)
   y2=288;
if(x2<0)
   x2=384;
g.fillRect(0,130,400,40);
g.fillRect(180,0,40,305);
g.setColor(Color.white);
for(int i=0;i<20;i++)
{
   if(i!=9 && i!=10)
    g.drawLine(i*20,150,i*20+10,150);
}
for(int j=0;j<15;j++)
{
   if(j!=7 && j!=8)
    g.drawLine(200,j*20,200,j*20+10);
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote