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

hey hi, i want a simple java program has two frames the first frame has an oval

ID: 3615845 • Letter: H

Question

hey hi,

i want a simple java program

has two frames

the first frame has an oval moving from left to right

when it reaches the right end of the frame it moves to the secondframe and keep moving tell it reaches the right end of the secondframe and stops

that's it :)

i hope u can help me and i will rate u ( 10 points ) if you give mewhat i asked for

Explanation / Answer

import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TwoFrames {    public static JPanel panel1, panel2;    public static Graphics g;    public static int x1, x2;    public static Timer t;       public static void main(String[] args) {        JFrame frame1 = newJFrame("Frame 1");        JFrame frame2 = newJFrame("Frame 2");               panel1 = new JPanel();        panel2 = new JPanel();        panel1.setPreferredSize(newDimension(200, 100));        panel2.setPreferredSize(newDimension(200, 100));        frame1.getContentPane().add(panel1);        frame2.getContentPane().add(panel2);               frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);               frame1.setLocation(0, 0);        frame1.getContentPane().add(panel1);        frame1.pack();        frame1.setVisible(true);               frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);               frame2.setLocation(208,0);        frame2.getContentPane().add(panel2);        frame2.pack();        frame2.setVisible(true);               x1 = 0;        x2 = -10;        t = new Timer(10, newActionListener() {            publicvoid actionPerformed(ActionEvent e) {               x1++;               if (x1 >= 190) {                   x2++;                   g =panel2.getGraphics();                   g.fillOval(x2, 40, 20,20);               } else {                   g =panel1.getGraphics();                   g.fillOval(x1, 40, 20,20);               }               if (x2 >= 178) {                   t.stop();               }               if (x1 % 5 == 0 || x2 % 5 == 0) {                   panel1.repaint();                   panel2.repaint();               }            }        });        t.start();    } }