• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

College Assignment

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
//Gym Booking Appointment Assignment

import java.awt.*;
import java.awt.event.ActionListener;
import java.applet.Applet;

public class GymBooking extends Applet implements ItemSelectable, ActionListener {

private Button totalcost, edit, finish;
private TextField day1, day2, day3, day4, day5, day6,
month1, month2, month3, month4, month5, month6,
year1, year2, year3, year4, year5, year6,
name, housenumber, postcode;
private TextAreaorder;
private Choice table1, table2, table3, table4, table5, table6;


public void init(){
setSize(600,500);
setLayout(null);

totalcost = new Button("Press here");
add(totalcost);
totalcost.addActionListener(this);
totalcost.setBounds(200,300,70,20);

edit = new Button("Press here");
add(edit);
edit.addActionListener(this);
edit.setBounds(200,340,70,20);

finish = new Button("Press here");
add(finish);
finish.addActionListener(this);
finish.setVisible(false);
finish.setBounds(200,480,70,20);

day1 =new TextField ("",20);
add (day1);
day1.setBounds(250,50,40,20);

month1=new TextField ("",20);
add (month1);
month1.setBounds(300,50,40,20);

year1=new TextField ("",20);
add (year1);
year1.setBounds(350,50,40,20);

day2 =new TextField ("",20);
add (day2);
day2.setBounds(250,90,40,20);

month2=new TextField ("",20);
add (month2);
month2.setBounds(300,90,40,20);

year2=new TextField ("",20);
add (year2);
year2.setBounds(350,90,40,20);

day3 =new TextField ("",20);
add (day3);
day3.setBounds(250,130,40,20);

month3=new TextField ("",20);
add (month3);
month3.setBounds(300,130,40,20);

year3=new TextField ("",20);
add (year3);
year3.setBounds(350,130,40,20);

day4 =new TextField ("",20);
add (day4);
day4.setBounds(250,170,40,20);

month4=new TextField ("",20);
add (month4);
month4.setBounds(300,170,40,20);

year4=new TextField ("",20);
add (year4);
year4.setBounds(350,170,40,20);

day5 =new TextField ("",20);
add (day5);
day5.setBounds(250,210,40,20);

month5=new TextField ("",20);
add (month5);
month5.setBounds(300,210,40,20);

year5=new TextField ("",20);
add (year5);
year5.setBounds(350,210,40,20);

day6 =new TextField ("",20);
add (day6);
day6.setBounds(250,250,40,20);

month6=new TextField ("",20);
add (month6);
month6.setBounds(300,250,40,20);

year6=new TextField ("",20);
add (year6);
year6.setBounds(350,250,40,20);

name=new TextField ("",20);
add (name);
name.addActionListener(this);
name.setVisible(false);
name.setBounds(180,370,200,20);

housenumber=new TextField ("",20);
add (housenumber);
housenumber.addActionListener(this);
housenumber.setVisible(false);
housenumber.setBounds(250,400,40,20);

postcode=new TextField ("",20);
add (postcode);
postcode.addActionListener(this);
postcode.setVisible(false);
postcode.setBounds(250,430,60,20);

table1 = new Choice();
table1.addItem("Gym");
table1.addItem("Swimming");
table1.addItem("Massage");
table1.addItem("Tennis");
table1.addItem("Sports Hall");
table1.addItem("Sauna");
add(table1);
table1.setBounds(150,50,80,300);

table2 = new Choice();
table2.addItem("Gym");
table2.addItem("Swimming");
table2.addItem("Massage");
table2.addItem("Tennis");
table2.addItem("Sports Hall");
table2.addItem("Sauna");
add(table2);
table2.setBounds(150,90,80,300);

table3 = new Choice();
table3.addItem("Gym");
table3.addItem("Swimming");
table3.addItem("Massage");
table3.addItem("Tennis");
table3.addItem("Sports Hall");
table3.addItem("Sauna");
add(table3);
table3.setBounds(150,130,80,300);

table4 = new Choice();
table4.addItem("Gym");
table4.addItem("Swimming");
table4.addItem("Massage");
table4.addItem("Tennis");
table4.addItem("Sports Hall");
table4.addItem("Sauna");
add(table4);
table4.setBounds(150,170,80,300);

table5 = new Choice();
table5.addItem("Gym");
table5.addItem("Swimming");
table5.addItem("Massage");
table5.addItem("Tennis");
table5.addItem("Sports Hall");
table5.addItem("Sauna");
add(table5);
table5.setBounds(150,210,80,300);

table6 = new Choice();
table6.addItem("Gym");
table6.addItem("Swimming");
table6.addItem("Massage");
table6.addItem("Tennis");
table6.addItem("Sports Hall");
table6.addItem("Sauna");
add(table6);
table6.setBounds(150,250,80,300);

order=new TextArea("Order\n" +
"---------------------------------\n",800,200);
add(order);
order.setEnabled(false);
order.setBounds(400,50,150,230);
}



public boolean action(Event event, Object object) {
if (event.target == table1) {
String selection = table1.getSelectedItem();
if (selection.equals("Gym"))
doChoice1Action();
else if (selection.equals("Massage"))
doChoice2Action();
else if (selection.equals("Swimming"))
doChoice3Action();
else if (selection.equals("Tennis"))
doChoice4Action();
else if (selection.equals("Sports Hall"))
doChoice5Action();
else if (selection.equals("Sauna"))
doChoice6Action();
}
if (event.target == table2) {
String selection = table2.getSelectedItem();
if (selection.equals("Gym"))
doChoice1Action();
else if (selection.equals("Massage"))
doChoice2Action();
else if (selection.equals("Swimming"))
doChoice3Action();
else if (selection.equals("Tennis"))
doChoice4Action();
else if (selection.equals("Sports Hall"))
doChoice5Action();
else if (selection.equals("Sauna"))
doChoice6Action();}
if (event.target == table3) {
String selection = table3.getSelectedItem();
if (selection.equals("Gym"))
doChoice1Action();
else if (selection.equals("Massage"))
doChoice2Action();
else if (selection.equals("Swimming"))
doChoice3Action();
else if (selection.equals("Tennis"))
doChoice4Action();
else if (selection.equals("Sports Hall"))
doChoice5Action();
else if (selection.equals("Sauna"))
doChoice6Action();}
if (event.target == table4) {
String selection = table4.getSelectedItem();
if (selection.equals("Gym"))
doChoice1Action();
else if (selection.equals("Massage"))
doChoice2Action();
else if (selection.equals("Swimming"))
doChoice3Action();
else if (selection.equals("Tennis"))
doChoice4Action();
else if (selection.equals("Sports Hall"))
doChoice5Action();
else if (selection.equals("Sauna"))
doChoice6Action();}
if (event.target == table5) {
String selection = table5.getSelectedItem();
if (selection.equals("Gym"))
doChoice1Action();
else if (selection.equals("Massage"))
doChoice2Action();
else if (selection.equals("Swimming"))
doChoice3Action();
else if (selection.equals("Tennis"))
doChoice4Action();
else if (selection.equals("Sports Hall"))
doChoice5Action();
else if (selection.equals("Sauna"))
doChoice6Action();}
if (event.target == table6) {
String selection = table6.getSelectedItem();
if (selection.equals("Gym"))
doChoice1Action();
else if (selection.equals("Massage"))
doChoice2Action();
else if (selection.equals("Swimming"))
doChoice3Action();
else if (selection.equals("Tennis"))
doChoice4Action();
else if (selection.equals("Sports Hall"))
doChoice5Action();
else if (selection.equals("Sauna"))
doChoice6Action();}
return false;
}

private void doChoice1Action() {
order.append("Gym = �2.50 \n");
}

private void doChoice2Action() {
order.append("Massage = �3.00\n");
}

private void doChoice3Action() {
order.append("Swimming = �2.00\n");
}

private void doChoice4Action() {
order.append("Tennis = �2.50\n");
}

private void doChoice5Action() {
order.append("Sports Hall = �5.00\n");
repaint();
}

private void doChoice6Action() {
order.append("Sauna = �3.00\n");
repaint();
}

public void paint(Graphics g){
g.drawString("Gym Online Booking Form",150,20);
g.drawString("Date",255,40);
g.drawString("Month",305,40);
g.drawString("Year",355,40);
g.drawString("First Booking",40,60);
g.drawString("Second Booking",40,100);
g.drawString("Third Booking",40,140);
g.drawString("Fourth Booking",40,180);
g.drawString("Fifth Booking",40,220);
g.drawString("Sixth Booking",40,260);
g.drawString("Please enter your name",40,390);
g.drawString("Please enter your house number", 60,410);
g.drawString("Pease enter your postcode",80,440);
g.drawString("Is your order correct?",80,320);
g.drawString("If not",80,350);

g.drawRect(35,40,100,30);
g.drawRect(35,80,100,30);
g.drawRect(35,120,100,30);
g.drawRect(35,160,100,30);
g.drawRect(35,200,100,30);
g.drawRect(35,240,100,30);

g.drawRect(350,50,40,20);
g.drawRect(300,50,40,20);
g.drawRect(250,50,40,20);

g.drawRect(250,90,40,20);
g.drawRect(300,90,40,20);
g.drawRect(350,90,40,20);

g.drawRect(250,130,40,20);
g.drawRect(300,130,40,20);
g.drawRect(350,130,40,20);

g.drawRect(250,130,40,20);
g.drawRect(300,130,40,20);
g.drawRect(350,130,40,20);

g.drawRect(250,170,40,20);
g.drawRect(300,170,40,20);
g.drawRect(350,170,40,20);

g.drawRect(250,210,40,20);
g.drawRect(300,210,40,20);
g.drawRect(350,210,40,20);

g.drawRect(250,250,40,20);
g.drawRect(300,250,40,20);
g.drawRect(350,250,40,20);
}


}

Above is the code that i have done for my course so far. I am having a few problems though. I have made a few text fields invisible but do not know how to get the rest of the writing invisible(the g.drawstrings for name, hose number and postcode). Also i would like the first button to make the code visible again. The other button should delete and information that has been inputted.

Thanks in advance guys i need help today preferably as the coursework needs to bein at 2pm tomorrow.
 
ant williams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
update : the only part of the work i need help on now is the edit button so that it will delete the information from the text area and text fields.

so far i have got

if (event.getSource()==edit){

i just dont know what code will delete all the data that has been inputted into the applet
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic