Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the codes below, create and use lambda expressions in a GUI. package AL_lambda; //LambdaExcercise import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.function.Function;

Using the codes below, create and use lambda expressions in a GUI.

package AL_lambda;

//LambdaExcercise

import java.awt.BorderLayout;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.function.Function;

import javax.swing.Box;

import javax.swing.BoxLayout;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class LambdaExercise {

// The input and output components

private static JTextField txtStatement = new JTextField(50);

private static JTextField txtResponse = new JTextField("Your response will appear here");

private static JButton btnLower = new JButton("Lower Case");

private static JButton btnUpper = new JButton("Upper Case");

private static JButton btnBackwards = new JButton("Backwards");

// DEFINE static lambda expressions here

public static void main(String[] args) {

JFrame frame = new JFrame("Lambda Exercise");

setupFrame(frame);

addActionListeners(frame);

}

private static void addActionListeners(JFrame frame) {

// ADD ACTION LISTENERS HERE

}

private static void setupFrame(JFrame frame) {

frame.setLayout(new BorderLayout());

frame.setLocationRelativeTo(null);

JLabel lblInstructions = new JLabel("Enter a statement to evaluate: ");

txtResponse.setEnabled(false);

JPanel pnlData = new JPanel();

pnlData.setLayout(new BoxLayout(pnlData, BoxLayout.Y_AXIS));

pnlData.add(lblInstructions);

pnlData.add(txtStatement);

pnlData.add(txtResponse);

JPanel pnlButtons = new JPanel();

pnlButtons.setLayout(new FlowLayout());

pnlButtons.add(btnLower);

pnlButtons.add(btnUpper);

pnlButtons.add(btnBackwards);

frame.add(pnlButtons, BorderLayout.SOUTH);

frame.add(pnlData, BorderLayout.CENTER);

frame.pack();

frame.setVisible(true);

}

}

//Lambda ActionListener

package AL_lambda;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.function.Function;

import java.util.function.Predicate;

import javax.swing.JOptionPane;

import javax.swing.text.JTextComponent;

public class LambdaActionListener implements ActionListener {

Function lambdaExpression;

JTextComponent input;

JTextComponent output;

public LambdaActionListener(Function lambdaExpression,

JTextComponent input,

JTextComponent output) {

this.lambdaExpression = lambdaExpression;

this.input = input;

this.output = output;

}

@Override

public void actionPerformed(ActionEvent e) {

// PLACE YOUR CODE HERE

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

What is Ramayana, who is its creator, why was Ramayana written?

Answered: 1 week ago

Question

To solve by the graphical methods 2x +3y = 9 9x - 8y = 10

Answered: 1 week ago