X


Payment

Question

In java language

Write code fragments to create a timer object that is firedevery 10 seconds. Every 10 seconds, the background color of thewindow changes to a new random color.

Write the timer-related code that would go in the constructorand the completelistener class.

For full credit, use a timer object of type javax.swing.Timerand a listener class that implements ActionListener.

Solution

xxxxxx go xxxxxxx the xxxx xxx xxxxxxxx for xxxxxxxxxxx :


import xxxx.xxx.xxxxx;xxxxxx xxxx.xxx.xxxxx.xxxxxxxxxxx;xxxxxx xxxx.xxx.xxxxx.xxxxxxxxxxxxxx;xxxxxx java.util.Random;

import xxxxx.xxxxx.xxxxxxx;xxxxxx javax.swing.JFrame;
import xxxxx.xxxxx.xxxxxx;xxxxxx xxxxx.xxxxx.xxxxx;xxxxxx xxxxx RandomColorChanger xxxxxxxxxx ActionListener{
final xxx xxxxY = 1000;
Color[] x = {xxxxx.xxx, xxxxx.xxxxx, xxxxx.xxxx, Color.BLACK,Color.WHITE, xxxxx.Yxxxxx}; // xxxxy xx xxxxx predefined
final xxx MAXCOLOR = x.xxxxxx; // choosing x color
JButton[] xx = xxx JButton[3];
Random x = xxxx;xxxxxx xxxxxxxxxxxxxxxxxx(){ // changing xxx color xxxxxxxy&#xxx;&#xxx;&#xxx; x = new xxxxxx();}xxxxxxx void xxxx(){&#xxx;&#xxx;&#xxx; xxxxxx x = xxx JFrame("RandomColorChanger"); //xxxxxx xxx xxxxxx frame
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    xxxxxx p = xxx xxxxxx();&#xxx;&#xxx;&#xxx; JButton x = xxxx;&#xxx;&#xxx;&#xxx; xxx(xxx x=x; i<3; x++){&#xxx;&#xxx;&#xxx;&#xxx;&#xxx; b = xxxxxxxxxx(xxxxxxx.xxxxxxxx(x));&#xxx;&#xxx;&#xxx;&#xxx;&#xxx; x.xxx(x);&#xxx;&#xxx;&#xxx;&#xxx;&#xxx; jb[i] = b;
    }&#xxx;&#xxx;&#xxx; x.xxx(x);&#xxx;&#xxx;&#xxx; x.xxxx();&#xxx;&#xxx;&#xxx; f.setVisible(true);
    xxxxx t = xxx xxxxx(xxxxY, this); // setting xxxxxxxx xx xxxxxx the xxxxx randomly
    x.xxxxx(); // xxxxxxxx the xxxxx}@xxxxxxxxxxxxxx void xxxxxxxxxxxxxxx(xxxxxxxxxxx x){&#xxx;&#xxx;&#xxx; xxx(xxx i=0; x&xx;x; i++){
     jb[i].setBackground(c[r.nextInt(MAXCOLOR)]);
    }}xxxxxx xxxxxx xxxx main(String[] xxxx){&#xxx;&#xxx;&#xxx; new xxxxxxxxxxxxxxxxxx().xxxx();}}

Payment



Payment