-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirtualCookingAssistantGUI.java
More file actions
201 lines (168 loc) · 8.64 KB
/
VirtualCookingAssistantGUI.java
File metadata and controls
201 lines (168 loc) · 8.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
public class VirtualCookingAssistantGUI extends JFrame {
private JTextArea recipeTextArea;
private JButton startButton;
private JButton nutritionalInfoButton;
private JTextArea nutritionalInfoTextArea;
private JTextArea cookingInstructionsTextArea;
private JButton nextStepButton;
private JButton suggestSubstitutionButton;
private JTextArea substitutionSuggestionsTextArea;
private ArrayList<String> cookingSteps;
private int currentStepIndex;
public VirtualCookingAssistantGUI() {
setTitle("Virtual Cooking Assistant");
setSize(800, 600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new BorderLayout());
getContentPane().setBackground(Color.BLACK); // Set background color
// Initialize components
recipeTextArea = new JTextArea();
startButton = new JButton("Start Cooking");
nutritionalInfoButton = new JButton("Nutritional Information");
nutritionalInfoTextArea = new JTextArea();
cookingInstructionsTextArea = new JTextArea();
nextStepButton = new JButton("Next Step");
suggestSubstitutionButton = new JButton("Suggest Substitutions");
substitutionSuggestionsTextArea = new JTextArea();
// Set fonts and colors
Font buttonFont = new Font("Arial", Font.BOLD, 16);
Color buttonColor = (Color.WHITE); // White
recipeTextArea.setBackground(Color.DARK_GRAY); // Set text area background color
recipeTextArea.setForeground(Color.WHITE); // Set text area text color
recipeTextArea.setFont(new Font("Arial", Font.PLAIN, 14)); // Set text area font
startButton.setFont(buttonFont);
startButton.setBackground(buttonColor);
startButton.setForeground(Color.BLACK);
nutritionalInfoButton.setFont(buttonFont);
nutritionalInfoButton.setBackground(buttonColor);
nutritionalInfoButton.setForeground(Color.BLACK);
nutritionalInfoTextArea.setBackground(Color.DARK_GRAY); // Set text area background color
nutritionalInfoTextArea.setForeground(Color.WHITE); // Set text area text color
nutritionalInfoTextArea.setFont(new Font("Arial", Font.PLAIN, 14)); // Set text area font
cookingInstructionsTextArea.setBackground(Color.DARK_GRAY); // Set text area background color
cookingInstructionsTextArea.setForeground(Color.WHITE); // Set text area text color
cookingInstructionsTextArea.setFont(new Font("Arial", Font.PLAIN, 14)); // Set text area font
nextStepButton.setFont(buttonFont);
nextStepButton.setBackground(buttonColor);
nextStepButton.setForeground(Color.BLACK);
suggestSubstitutionButton.setFont(buttonFont);
suggestSubstitutionButton.setBackground(buttonColor);
suggestSubstitutionButton.setForeground(Color.BLACK);
substitutionSuggestionsTextArea.setBackground(Color.DARK_GRAY); // Set text area background color
substitutionSuggestionsTextArea.setForeground(Color.WHITE); // Set text area text color
substitutionSuggestionsTextArea.setFont(new Font("Arial", Font.PLAIN, 14)); // Set text area font
// Set borders
Border textBorder = new LineBorder(Color.WHITE, 2); // Set text area border
recipeTextArea.setBorder(textBorder);
nutritionalInfoTextArea.setBorder(textBorder);
cookingInstructionsTextArea.setBorder(textBorder);
substitutionSuggestionsTextArea.setBorder(textBorder);
// Add components to the frame
JPanel recipePanel = new JPanel(new BorderLayout());
recipePanel.setBackground(Color.BLACK);
JLabel recipeLabel = new JLabel("Recipe:");
recipeLabel.setForeground(Color.WHITE); // Set label text color to white
recipePanel.add(recipeLabel, BorderLayout.NORTH);
recipePanel.add(new JScrollPane(recipeTextArea), BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.setBackground(Color.BLACK);
buttonPanel.add(startButton);
buttonPanel.add(nutritionalInfoButton);
JPanel nutritionalInfoPanel = new JPanel(new BorderLayout());
nutritionalInfoPanel.setBackground(Color.BLACK);
JLabel nutritionalInfoLabel = new JLabel("Nutritional Information:");
nutritionalInfoLabel.setForeground(Color.WHITE); // Set label text color to white
nutritionalInfoPanel.add(nutritionalInfoLabel, BorderLayout.NORTH);
nutritionalInfoPanel.add(new JScrollPane(nutritionalInfoTextArea), BorderLayout.CENTER);
JPanel cookingInstructionsPanel = new JPanel(new BorderLayout());
cookingInstructionsPanel.setBackground(Color.BLACK);
JLabel cookingInstructionsLabel = new JLabel("Cooking Instructions:");
cookingInstructionsLabel.setForeground(Color.WHITE); // Set label text color to white
cookingInstructionsPanel.add(cookingInstructionsLabel, BorderLayout.NORTH);
cookingInstructionsPanel.add(new JScrollPane(cookingInstructionsTextArea), BorderLayout.CENTER);
cookingInstructionsPanel.add(nextStepButton, BorderLayout.SOUTH);
JPanel substitutionPanel = new JPanel(new BorderLayout());
substitutionPanel.setBackground(Color.BLACK);
JLabel substitutionLabel = new JLabel("Ingredient Substitution Suggestions:");
substitutionLabel.setForeground(Color.WHITE); // Set label text color to white
substitutionPanel.add(substitutionLabel, BorderLayout.NORTH);
substitutionPanel.add(new JScrollPane(substitutionSuggestionsTextArea), BorderLayout.CENTER);
substitutionPanel.add(suggestSubstitutionButton, BorderLayout.SOUTH);
add(recipePanel, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
add(nutritionalInfoPanel, BorderLayout.EAST);
add(cookingInstructionsPanel, BorderLayout.WEST);
add(substitutionPanel, BorderLayout.NORTH);
// Add action listeners
startButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
startCooking();
}
});
nutritionalInfoButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
displayNutritionalInfo();
}
});
nextStepButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
displayNextStep();
}
});
suggestSubstitutionButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
suggestSubstitutions();
}
});
setVisible(true);
}
private void startCooking() {
cookingSteps = new ArrayList<>(Arrays.asList(cookingInstructionsTextArea.getText().split("\n"))); // Split text by newline and convert to ArrayList
System.out.println(cookingSteps);
// Reset the cooking instructions
cookingInstructionsTextArea.setText("");
currentStepIndex = 0;
// Display the first cooking step
displayNextStep();
JOptionPane.showMessageDialog(null, "Cooking started!");
}
private void displayNextStep() {
if (currentStepIndex < cookingSteps.size()) {
String currentStep = cookingSteps.get(currentStepIndex);
cookingInstructionsTextArea.append((currentStepIndex + 1) + ". " + currentStep + "\n");
currentStepIndex++;
} else {
JOptionPane.showMessageDialog(null, "No more steps.");
}
}
private void displayNutritionalInfo() {
// Hardcoded nutritional information for demonstration purposes
String nutritionalInfo = "Calories: 300\nProtein: 15g\nCarbohydrates: 45g\nFat: 8g\nAllergens: None";
nutritionalInfoTextArea.setText(nutritionalInfo);
}
private void suggestSubstitutions() {
// Hardcoded substitution suggestions for demonstration purposes
String substitutionSuggestions = "Flour -> Whole wheat flour\nSugar -> Honey\nButter -> Coconut oil";
substitutionSuggestionsTextArea.setText(substitutionSuggestions);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new VirtualCookingAssistantGUI();
}
});
}
}