Hi everyone!
So I have a problem with java applet.
import java.awt.*;
import java.applet.*;
// import an extra class for the ActionListener
import java.awt.event.*;
// Tells the applet you will be using the ActionListener methods.
public class project extends Applet implements ActionListener
{
TextField nameField;
Checkbox cb1;
Checkbox cb2;
Checkbox cb3;
Checkbox cb4;
Checkbox option;
Choice cho;
Button okButton;
Button resetButton;
String s;
FlowLayout f;
public void init(){
setLayout(new FlowLayout());
okButton = new Button("Submit");
resetButton = new Button("Reset");
nameField = new TextField("Your name",35);
radioGroup = new CheckboxGroup();
add(new Label("What's your name?"));
add(nameField);
ch1 = new Checkbox("Music", radioGroup,false);
ch2 = new Checkbox("Computers", radioGroup,true);
ch3 = new Checkbox("Sport", radioGroup,false);
ch4 = new Checkbox("TV", radioGroup,false);
add(new Label("What country are you from?"));
Choice c = new Choice();
c.addItem("Australia");
c.addItem("USA");
c.addItem("EU");
add(c);
add(new Label("What's your hobby?"));
add(ch1);
add(ch2);
add(ch3);
add(ch4);
add(okButton);
add(resetButton);
okButton.addActionListener(this);
resetButton.addActionListener(this);
}
public void paint(Graphics g){
if (ch1.getState()) g.setColor(Color.red); //I DIDN'T KNOW WHAT TO WRITE
else if (ch2.getState()) g.setColor(Color.blue);
else if (ch3.getState()) g.setColor(Color.yellow);
else g.setColor(Color.green);
g.drawString(nameField.getText(),20,180);
}
public boolean combocox(Event e, Object o){ //CHOICE FOR THE COMBOBOX
if (e.target instanceof Choice){
cho = (Choice) e.target;
MenuEvent=cho.getItem(cho.getSelectedIndex());
repaint();
}
public void actionPerformed(ActionEvent evt) {
//if (evt.getSource() == okButton){ - IT SHOULD OUTPUT ALERT OR MESSAGE BOX
repaint();
}
else if (evt.getSource() == resetButton){
// resetButton.setLabel("It's default!"); - IT SHOULD RESET ALL THE FIELDS
// nameField.setText("This is deafault text!");
repaint();
}
}
}
What it should do is first to imput your name in text field, then to select from which country are you (from the combo box), then to check some of the checkboxes about your hobby, and then to have 2 buttons reset and submit. Reset should reset all the fields and submit should output a message box with this contenet : Hello (your name from the text box), from (country from combobox), your hobby is (checkboxes)....and ...and.
And to check for empty text field.
I'll be soooo grateful if someone help me with this, because I really want to learn how to do this.
Thank you.