Question
With the Code below, how do i add code so that when the Search Recipe button is pressed, it will do a google search using
With the Code below, how do i add code so that when the "Search Recipe" button is pressed, it will do a google search using the inputs in the text boxes to search the internet?
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
public class RecipeFinder {
public static void main(String[] args) {
//JFrame
JFrame frame = new JFrame("The Recipe Finder");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(400,400));
//JPanel
JPanel entry = new JPanel();
entry.setLayout(new BoxLayout(entry, BoxLayout.Y_AXIS));
//JLabel
JLabel insert = new JLabel("Insert Food/Ingredients");
entry.add(insert);
entry.setBackground(Color.red);
//JTextField(s)
JTextField foodOne = new JTextField();
foodOne.setMaximumSize(new Dimension(400,48));
foodOne.setMinimumSize(new Dimension(400,48));
entry.add(foodOne);
JTextField foodTwo = new JTextField();
foodTwo.setMaximumSize(new Dimension(400,48));
foodTwo.setMinimumSize(new Dimension(400,48));
entry.add(foodTwo);
//JButton(s)
JButton addTextBox = new JButton("Add");
addTextBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JTextField newBox = new JTextField();
newBox.setMaximumSize(new Dimension(400,48));
entry.add(newBox);
entry.revalidate();
frame.invalidate();
}
});
JButton search = new JButton("Search Recipes");
JPanel buttonPanel = new JPanel();
buttonPanel.add(addTextBox);
buttonPanel.add(search);
buttonPanel.setBackground(Color.blue);
JPanel rootPanel = new JPanel();
rootPanel.setLayout(new BorderLayout());
rootPanel.add(entry, BorderLayout.CENTER);
rootPanel.add(buttonPanel, BorderLayout.SOUTH);
JScrollPane rootEntry = new JScrollPane(rootPanel);
rootEntry.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
rootEntry.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
//FrameWork
frame.add(rootEntry);
frame.pack();
frame.setVisible(true);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started