// <APPLET code=Banner.class HEIGHT=60 WIDTH=400></APPLET> import java.applet.*; import java.awt.*; import java.awt.event.*; import java.net.*; // Interactive banner applet public class Banner extends Applet implements ActionListener { // create sub components Color bg = new Color(0,0,255); Label title = new Label("My Dream PC"); Label subtitle = new Label("from AlWill Computers"); Label lcpu = new Label("CPU:",Label.RIGHT); Choice cpu = new Choice(); Label lmem = new Label("Memory:",Label.RIGHT); Choice mem = new Choice(); Label lhard = new Label("Disk:",Label.RIGHT); Choice hard = new Choice(); Button go = new Button("Go!"); GridBagConstraints lout = new GridBagConstraints(); // initialize items public void init() { go.addActionListener(this); subtitle.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) // simulated hyperlink { URL website; try { website=new URL("http://www.al-williams.com"); getAppletContext().showDocument(website); } catch (Exception ev) { } } }); // set colors and add items lhard.setBackground(bg); lmem.setBackground(bg); lcpu.setBackground(bg); title.setBackground(bg); subtitle.setBackground(bg); title.setFont(new Font("SansSerif",Font.BOLD,18)); title.setForeground(new Color(255,255,0)); cpu.add("Pentium II"); cpu.add("Pentium III"); cpu.add("AMD K7"); mem.add("32M"); mem.add("64M"); mem.add("128M"); mem.add("256M"); hard.add("2G"); hard.add("5G"); hard.add("10G"); hard.add("20G"); setLayout(new GridBagLayout()); lout.gridx=0; lout.gridy=0; lout.anchor=GridBagConstraints.EAST; lout.gridwidth=2; add(title,lout); lout.gridwidth=1; lout.gridy++; add(lcpu,lout); lout.gridx++; lout.anchor=GridBagConstraints.WEST; add(cpu,lout); lout.gridx++; lout.anchor=GridBagConstraints.EAST; add(lmem,lout); lout.gridx++; lout.anchor=GridBagConstraints.WEST; add(mem,lout); lout.gridx++; lout.anchor=GridBagConstraints.EAST; add(lhard,lout); lout.gridx++; lout.anchor=GridBagConstraints.WEST; add(hard,lout); lout.gridx=3; lout.gridy=0; lout.anchor=GridBagConstraints.CENTER; add(go,lout); lout.gridx++; subtitle.setFont(new Font("SansSerif",Font.ITALIC,8)); add(subtitle,lout); // whew! done. } public void paint(Graphics g) { g.setColor(bg); // clear background g.fillRect(0,0,400,60); } // This is the handler for the go button public void actionPerformed(ActionEvent e) { if (e.getSource()==go) { // build query URL qry; StringBuffer query= new StringBuffer("http://www.al-williams.com/quote.php3?cpu="); query.append(URLEncoder.encode(cpu.getSelectedItem())); query.append("&mem="); query.append(URLEncoder.encode(mem.getSelectedItem())); query.append("&hard="); query.append(URLEncoder.encode(hard.getSelectedItem())); try { qry = new URL(query.toString()); getAppletContext().showDocument(qry); } catch (Exception e2) { } } } }