Examlex

Solved

Rewrite the Following Code to Use a Lambda Expression for the Button

question 18

Essay

Rewrite the following code to use a Lambda expression for the button action listener.
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
public class ButtonDemo3 extends JFrame
{
public ButtonDemo3 )
{
setSize250,100);
setDefaultCloseOperationJFrame.EXIT_ON_CLOSE);
setTitle"Button Demo");
Container contentPane = getContentPane );
contentPane.setBackgroundColor.BLUE);
contentPane.setLayoutnew FlowLayout ));
JButton goButton = new JButton"Green");
goButton.addActionListener
{ e } - > contentPane.setBackgroundColor.GREEN));
contentPane.addgoButton);
}
public static void mainString[] args)
{
ButtonDemo3 buttonGui = new ButtonDemo3 );
buttonGui.setVisibletrue);
}
}


Definitions:

Annual Cash Operating Inflows

Annual cash operating inflows refer to the total cash receipts a business receives from its operating activities during a fiscal year.

Salvage Value

The estimated residual value of an asset at the end of its useful life, reflecting what it can be sold for or scrapped.

Payback Period

The amount of time it takes for an investment to generate cash flow sufficient to recover its initial cost.

Operating Costs

Expenses associated with the day-to-day operations of a business, including rent, utilities, and payroll.

Related Questions