-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearch.java
163 lines (118 loc) · 3.51 KB
/
Search.java
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
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.helpers.DefaultHandler;
import javax.swing.*;
public class Search extends JFrame implements ActionListener
{
public JLabel zipLabel;
public JTextField zipField, resultField;
public JButton btnSearch, btnExit;
public Search()
{
setLayout(null);
setSize(700,750);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
zipLabel = new JLabel("Please Enter Your Zip Code:");
zipLabel.setBounds(100,0,200,200);
add(zipLabel);
zipField = new JTextField(10);
zipField.setBounds(100,120,200,25);
zipField.addActionListener(this);
add(zipField);
btnSearch = new JButton ("Search!");
btnSearch.setBounds(350,100,100,100);
btnSearch.addActionListener(this);
add(btnSearch);
btnExit = new JButton("Main Menu ");
btnExit.setBounds(500,500,100,100);
btnExit.addActionListener(this);
add(btnExit);
ImageIcon imageIcon = new ImageIcon("img/image1.jpg");
Image image = imageIcon.getImage();
}
public ImageIcon FoodImg;
public JLabel Fname;
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == btnSearch)
{
int zipValue;
zipValue = Integer.parseInt(zipField.getText());
repaint();
setBackground(Color.white);
System.out.println("Searching");
String name = pickFood();
System.out.println("Food "+ name);
result(name);
}
if (e.getSource() == btnExit)
{
userInterface i = new userInterface();
i.setVisible(true);
}
}
public void result(String foodName){
// repaint();
switch(foodName){
case "Pasta" :
FoodImg = new ImageIcon(getClass().getResource("Pasta.jpg"));
break;
case "Pizza" :
FoodImg = new ImageIcon(getClass().getResource("Pizza.jpg"));
break;
case "Seafood" :
FoodImg = new ImageIcon(getClass().getResource("Seafood.jpg"));
break;
case "Deli" :
FoodImg = new ImageIcon(getClass().getResource("Deli.jpg"));
break;
case "Frozen" :
FoodImg = new ImageIcon(getClass().getResource("Frozen.jpg"));
break;
case "Canned" :
FoodImg = new ImageIcon(getClass().getResource("Canned.jpg"));
break;
case "Wine" :
FoodImg = new ImageIcon(getClass().getResource("Wine.jpg"));
break;
case "Bakery" :
FoodImg = new ImageIcon(getClass().getResource("Bakery.jpg"));
break;
case "Fruit" :
FoodImg = new ImageIcon(getClass().getResource("Fruits.jpg"));
break;
case "Soup" :
FoodImg = new ImageIcon(getClass().getResource("Soup.jpg"));
break;
}
//FoodImg = new ImageIcon(getClass().getResource("Food-Finder.png"));
Fname = new JLabel(FoodImg);
Fname.setBounds(150,300,301,376);
add(Fname);
//remove(Fname);
}
public static String pickFood()
{
String foodName= " ";
String [] foodList = {"Pasta","Pizza","Seafood","Deli","Frozen","Canned","Wine","Bakery","Fruit","Soup"};
int pickNum = (int) (Math.random()*9);
foodName = foodList[pickNum];
return foodName;
}
}