import java.awt.*; import java.net.*; import java.io.*; import java.applet.*; import java.lang.*; import java.util.*; import gjt.ImageButton; import gjt.ImageButtonEvent; import gjt.ExclusiveImageButtonPanel; import gjt.Orientation; import gjt.Toolbar; public class Client extends Applet { private DisplayPanel dp; ToolbarPanel toolbarPanel; public myDatabase database = new myDatabase(); StringBuffer idList[]; ControlPanel controlPanel; CarData currentCar = new CarData(); int currNumCars, currCarNum; Image carPix; // Image a, b, c, d, e, f, g, h, i, j, k, l, m, n; ImageButton ser3but, ser5but, ser7but, ser8but, m3but, z3but; Image ser3, ser5, ser7, ser8, m3, z3; public void init() { ser3 = getImage(getCodeBase(), "3series.gif"); ser3but = new ImageButton(ser3); ser5 = getImage(getCodeBase(), "5series.gif"); ser5but = new ImageButton(ser5); ser7 = getImage(getCodeBase(), "7series.gif"); ser7but = new ImageButton(ser7); ser8 = getImage(getCodeBase(), "8series.gif"); ser8but = new ImageButton(ser8); m3 = getImage(getCodeBase(), "m3.gif"); m3but = new ImageButton(m3); z3 = getImage(getCodeBase(), "z3.gif"); z3but = new ImageButton(z3); setLayout(new BorderLayout()); toolbarPanel = new ToolbarPanel(this); add("South", new ControlPanel(this,database)); add("Center", dp = new DisplayPanel(this)); } public Client() { //myDatabase database = new myDatabase(); setBackground(Color.black); } public void showData(String id, String image, String name, String engine, String size, String price, String comments) { // CarData cd = new CarData(id, image, name, engine, size, price, comments); // dp.show(cd); // dp.repaint(); } public void getData(String a, String b, String c, String d, String e, String f, String g) { if (a.equals("")) { dp.showerr(); dp.repaint(); } else showData(a,b,c,d,e,f,g); } public void getRange(String low, String high) { database.open(); int num = database.getMatchCount(low, high); currNumCars = num; if (num == 0) { dp.showerr(); dp.repaint(); } // System.out.println("count ====== " + num); if (num > 0) { idList = new StringBuffer[num]; for (int j=0; j 0) { database.open(); currCarNum--; database.getCarInfo(idList[currCarNum], currentCar); carPix = getImage(getCodeBase(), currentCar.Img.toString()); dp.show(currentCar); dp.repaint(); database.close(); } } public void search(String a) { // myDatabase database = new myDatabase(); StringBuffer asb = new StringBuffer(); StringBuffer bsb = new StringBuffer(); StringBuffer csb = new StringBuffer(); StringBuffer dsb = new StringBuffer(); StringBuffer esb = new StringBuffer(); StringBuffer fsb = new StringBuffer(); StringBuffer gsb = new StringBuffer(); database.open(); ///////// // database.getIDList(low, high, idList); database.find(a, asb, bsb, csb, dsb, esb, fsb, gsb); System.out.println("got back from db: " + asb.toString()); getData(asb.toString(), bsb.toString(), csb.toString(), dsb.toString(), esb.toString(), fsb.toString(), gsb.toString()); database.close(); } } class ToolbarPanel extends Panel { Client father; ImageButton ser3but, ser5but, ser7but, ser8but, m3but, z3but; Image ser3, ser5, ser7, ser8, m3, z3; public ToolbarPanel(Client Father) { father = Father; System.out.println(father); setLayout(new FlowLayout()); add(father.ser3but); add(father.ser5but); add(father.ser7but); add(father.ser8but); add(father.m3but); add(father.z3but); } public boolean handleEvent(Event event) { return true; } public void paint(Graphics g) { update(g); } public void update(Graphics g) { Color bg = getBackground(); g.setColor(bg); Dimension dim = size(); g.draw3DRect(1,1,dim.width-2, dim.height-2,true); g.draw3DRect(4,4,dim.width-8, dim.height-8,false); } } class ControlPanel extends Panel { private Client parent; private List lst; private Choice c; private Label lbl; Panel search_car, search_price, bmw_logo; Button query_price; Choice c_low = new Choice(); Choice c_high = new Choice(); private myDatabase mdb; public ControlPanel(Client clt, myDatabase db) { parent = clt; mdb = db; setFont(new Font("Helvetica", Font.BOLD, 14)); setLayout(new BorderLayout(30,30)); search_price = new Panel(); bmw_logo = new Panel(); setForeground(Color.white); search_price.add(lbl = new Label("Choose the price range of the car:")); c_low.setBackground(Color.white); c_low.setForeground(Color.black); c_low.addItem("- Lower Bound -"); c_low.addItem("$00,000"); c_low.addItem("$10,000"); c_low.addItem("$20,000"); c_low.addItem("$30,000"); c_low.addItem("$40,000"); c_low.addItem("$50,000"); c_low.addItem("$60,000"); c_low.addItem("$70,000"); c_low.addItem("$80,000"); c_low.addItem("$90,000"); search_price.add(c_low); search_price.add(lbl = new Label(" and")); c_high.setBackground(Color.white); c_high.setForeground(Color.black); c_high.addItem("- Upper Bound -"); c_high.addItem("$00,000"); c_high.addItem("$10,000"); c_high.addItem("$20,000"); c_high.addItem("$30,000"); c_high.addItem("$40,000"); c_high.addItem("$50,000"); c_high.addItem("$60,000"); c_high.addItem("$70,000"); c_high.addItem("$80,000"); c_high.addItem("$90,000"); search_price.add(c_high); query_price = new Button("Query"); query_price.setBackground(Color.white); query_price.setForeground(Color.black); search_price.add(query_price); // add("Center",search_car); add("North",search_price); bmw_logo.add(parent.toolbarPanel); add("South",bmw_logo); } public boolean action(Event evt, Object arg) { if (evt.target == query_price) { System.out.println("Getting results"); parent.getRange(c_low.getSelectedItem(), c_high.getSelectedItem()); } return true; } } class DisplayPanel extends Panel { Client father; private CarData cdata; private boolean nodata = false; TextArea excomments; Panel commentsPanel; Panel next_prevPanel; Button next, previous; String nodatagot = "Query Returned nothing"; public DisplayPanel(Client cli) { father = cli; cdata=null; setFont( new Font("Times-Roman",Font.BOLD,22)); excomments = new TextArea("",3,80); excomments.setBackground(Color.cyan); excomments.setFont(new Font("Times-Roman",Font.BOLD,14)); commentsPanel = new Panel(); commentsPanel.setLayout(new GridLayout(2,1,20,20)); commentsPanel.add(excomments); next = new Button("Next Car"); previous = new Button("Previous Car"); next.setBackground(Color.cyan); previous.setBackground(Color.cyan); next_prevPanel = new Panel(); next_prevPanel.setLayout(new GridLayout(1,2,20,20)); next_prevPanel.add(previous); next_prevPanel.add(next); commentsPanel.add(next_prevPanel); setLayout(new BorderLayout()); add("South",commentsPanel); } public void show(CarData car) { cdata = car; } public void showerr() { cdata = null; nodata = true; } public void paint(Graphics g) { setBackground(Color.white); g.setColor(new java.awt.Color(0,0,0)); g.setFont( new Font("Times-Roman",Font.BOLD,18)); g.setColor(new java.awt.Color(0,0,0)); if(cdata!=null) { g.drawImage(father.carPix, 10, 10, 200,100,this); g.setFont( new Font("Times-Roman",Font.BOLD,18)); g.setColor(new java.awt.Color(0,0,0)); g.drawString("Id : " + cdata.Id, 220, 20); g.drawString("Name : " + cdata.Name, 220, 40); g.drawString("Engine : " + cdata.Engine, 220, 60); g.drawString("Size : " + cdata.Size, 220, 80); g.drawString("Price : " + cdata.Price, 220, 100); // g.drawImage(father.a, 75, 190, 50,50,this); excomments.setText(cdata.Comments.toString()); } if(cdata==null && (nodata)) { g.setFont( new Font("Helvetica",Font.BOLD,36)); g.setColor(new java.awt.Color(0,0,0)); g.drawString(nodatagot, 80, 100); } } public boolean action(Event evt, Object arg) { if (evt.target == next) { System.out.println("Next Hit"); father.getNextCar(); } else if (evt.target == previous) { System.out.println("Previous Hit"); father.getPreviousCar(); } /* if (evt.target instanceof Choice) { if (evt.target == c_low) lowVal = else if (evt.target == c_high) if (arg.equals("$20,000 - $39,999")) { // System.out.println("searching by price range: " + arg); //parent.search(arg.toString()); } else if (arg.equals("$40,000 - $59,999")) { //System.out.println("searching by price range: " + arg); //parent.search(arg.toString()); } else if (arg.equals("$60,000 - $79,999")) { //System.out.println("searching by price range: " + arg); //parent.search(arg.toString()); } else if (arg.equals("$80,000 - $99,999")) { //System.out.println("searching by price range: " + arg); //parent.search(arg.toString()); } else { System.out.println("GO AWAY"); } return true; } */ return true; } } class CarData { public StringBuffer Id; public StringBuffer Img; public StringBuffer Name; public StringBuffer Engine; public StringBuffer Size; public StringBuffer Price; public StringBuffer Comments; public CarData() { Id = new StringBuffer(""); Img = new StringBuffer(""); Name = new StringBuffer(""); Engine = new StringBuffer(""); Size = new StringBuffer(""); Price = new StringBuffer(""); Comments = new StringBuffer(""); } }