import awb.*; import java.awt.*; import java.awt.event.*; public class UsedCars extends java.applet.Applet implements ActionListener { TextField gMake, gStyle, gColor, gOwner, mInstruct; IntField gYear; String Make[] ={"Mercedes","Mercedes","Ford", "Mercedes","Datsun","Ford"}; String Style[]={"4 door", "4 door", "truck", "4 door", "2 door","4 door"}; String Color[]={"white", "ivory", "blue", "green", "red", "blue"}; String Owner[]={"M.Ramm", "D.Ramm", "M.Ramm","D.Ramm", "K.Ramm","D.Ramm"}; int Year[] ={ 1987, 1987, 1972, 1971, 1978, 1978}; Label make, style, color, owner, year; Button bSearch; TextArea mResults; int size = 6; public void init() { year = new Label("Year"); make = new Label("Make"); style = new Label("Style"); color = new Label("Color"); owner = new Label("Owner"); mInstruct = new TextField(60); mInstruct.setText("Enter Selections, leave blank for Wild Card"); gYear = new IntField(10); gMake = new TextField(10); gStyle = new TextField(10); gColor = new TextField(10); gOwner = new TextField(20); bSearch = new Button("Search"); mResults = new TextArea(10, 60); bSearch.addActionListener(this); gMake.addActionListener(this); add(mInstruct); add(year); add(gYear); add(make); add(gMake); add(style); add(gStyle); add(color); add(gColor); add(owner); add(gOwner); add(bSearch); add(mResults); } public void actionPerformed(ActionEvent event) { //Object cause = event.getSource(); int yea; String mak, sty, col, own; //if (cause == bSearch) { yea = gYear.getInt(); mak = gMake.getText(); sty = gStyle.getText(); col = gColor.getText(); own = gOwner.getText(); mResults.setText("Cars Matching Parameters Specified\n"); report(yea, mak, sty, col, own, size); } } boolean isMatch(int year, int yea, String make, String mak, String style, String sty, String color, String col, String owner, String own) { if ((year == yea || yea == 0) && (make.equals(mak) ||mak.equals("")) && (style.equals(sty)||sty.equals("")) && (color.equals(col)||col.equals("")) && (owner.equals(own)||own.equals("")) ) return true; return false; } void report(int yea, String mak, String sty, String col, String own, int num) { int k = 0; while (k < num) { if (isMatch(Year[k], yea, Make[k], mak, Style[k], sty, Color[k], col, Owner[k], own)) mResults.append("year: "+Year[k]+" make: "+Make[k]+" style: " +Style[k]+" color: "+Color[k]+" owner: "+Owner[k]+"\n"); k = k + 1; } } }