|
myRequest code
The code is attached below my post thread or should I paste it here
import java.awt.*; //import the whole awt package
import javax.swing.JApplet; //import class JApplet
import java.awt.Graphics; //import class Graphics
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.*;
public class myRequest extends java.applet.Applet implements ActionListener{
//Create chekboxes which determine the kind of interaction the user wants
CheckboxGroup theGroup = new CheckboxGroup();
Checkbox c1 = new Checkbox("Distances", theGroup, true);
Checkbox c2 = new Checkbox("Health Facilities", theGroup, false);
Checkbox c3 = new Checkbox("Hotels & Accomondation", theGroup, false);
Checkbox c4 = new Checkbox("Government Offices", theGroup, false);
Checkbox c5 = new Checkbox("Supermarkets", theGroup, false);
Checkbox c6 = new Checkbox("Banks", theGroup, false);
//Create Choices so as to have a selection
Choice menus = new Choice();
Choice menus2 = new Choice();
//Create labels to indicate what happpens at each place
Label whereFrom = new Label("Where do you want to know?");
Label whereTo = new Label("Select the nearest point to where you are!");
//Label jeddy = new Label("Go to room D310");
//A button to send the selected request
Button report = new Button("Get Direction");
//Just to format font if I use g.drawString instead of the Label text
Font mm = new Font("Arial", Font.BOLD, 15);
//Add action listener
public void ActionPerformed(ActionEvent evt){
if (evt.getActionCommand().equals("Distances")){
setC1();
}
if (evt.getActionCommand().equals("Health Facilities")){
setC2();
}
if (evt.getActionCommand().equals("Hotels & Accomondation")){
setC3();
}
if (evt.getActionCommand().equals("Government Offices")){
setC4();
}
if (evt.getActionCommand().equals("Supermarkets")){
setC5();
}
if (evt.getActionCommand().equals("Banks")){
setC6();
}
repaint();
}
public void setC1(){
whereFrom.setText("Where do you want to know?");
whereTo.setText("Select the nearest point to where you are!");
report.setLabel("Get Direction"); }
public void setC2(){
whereFrom.setText("Which hospital are you interested in?");
whereTo.setText("Select the nearest point to where you are!");
report.setLabel("Take me there"); }
public void setC3(){
whereFrom.setText("What Star hotel?");
whereTo.setText("Select the nearest point to where you are!");
report.setLabel("Give me a list"); }
public void setC4(){
whereFrom.setText("What Office are you interested in?");
whereTo.setText("Select the nearest point to where you are!");
report.setLabel("Show the office"); }
public void setC5(){
whereFrom.setText("Select the supermarket you are looking for?");
whereTo.setText("Select the nearest point to where you are!");
report.setLabel("Get direction and prices"); }
public void setC6(){
whereFrom.setText("Which bank do you want?");
whereTo.setText("Select the nearest point to where you are!");
report.setLabel("Get bank and ATM's"); }
/** Initialization method that will be called after the applet is loaded
* into the browser.
*/
public void init() {
c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
c4.addItemListener(this);
c5.addItemListener(this);
c6.addItemListener(this);
menus.add("Select One");
menus.add("City Hall");
menus.add("Hilton");
menus.add("Nation Center");
menus.add("National Archives");
menus.add("680 Hotel");
menus.add("Electricity House");
menus.add("Times tower");
menus.addItem("Harambee House");
menus.addItem("Anniversary towers");
menus.addItem("Viewpark towers");
menus.addItem("Serena hotel");
menus.addItem("Nakumatt Lifestyle");
menus.addItem("I & M House");
menus.addItem("Barclays Head Office");
menus2.add("Select One");
menus2.add("City Hall");
menus2.add("Hilton");
menus2.add("Nation Center");
menus2.add("National Archives");
menus2.add("680 Hotel");
menus2.add("Electricity House");
menus2.add("Times tower");
menus2.addItem("Harambee House");
menus2.addItem("Anniversary towers");
menus2.addItem("Viewpark towers");
menus2.addItem("Serena hotel");
menus2.addItem("Nakumatt Lifestyle");
menus2.addItem("I & M House");
menus2.addItem("Barclays Head Office");
add(whereFrom);
add(whereTo);
add(menus);
add(menus2);
add(report);
add(c1);
add(c6);
add(c3);
add(c4);
add(c5);
add(c2);
// TODO start asynchronous download of heavy resources
}
public void paint(Graphics g) {
//Set positions for the Checkboxes
c1.setLocation(13,25);
c2.setLocation(120,25);
c3.setLocation(120,65);
c4.setLocation(120,45);
c5.setLocation(13,65);
c6.setLocation(13,45);
g.drawRect(5,3,275,100);
/**This part represents where I've used g.drawstring */
g.setFont(mm);
g.setColor(Color.BLUE);
g.drawString("What Help would you like on ?" , 8,19);
//g.drawString("Where do you want to know?" ,10 ,25);
//g.drawRect(5,10,180,25);
// g.drawString("Select the nearest point to where you are!",3, 130);
//g.drawRect(1,115,240,25);
/**This part I've used Labels */
whereFrom.setLocation(10,115);
whereTo.setLocation(6, 180);
/*These are the Choices */
menus.setLocation(15,140);
menus2.setLocation(15,210);
report.setLocation(180,250);
//g.drawString("Rm D310",15, 300);
//jeddy.setLocation(78,300);
}
}
|