Link to home
Start Free TrialLog in
Avatar of susanbirnbaum
susanbirnbaum

asked on

Urgently need ahosang...

Hi there,

ahosang, since your applet was such a success here at our workplace, we wondered if you could adjust the same applet program to do a few new things.

The recent one had a new frame window which we still want.  The first applet window should like a small form with two textfields, where the user enters their email address and password.

The email textfield should have 2 validation checks:
1)The first number should not be numeric.
2)It should check for the '@' at sign in the email address.

The password should be COMMUNITYSYS.

There are 2 buttons below - OK and CLEAR.
When the user clicks "OK" it should open a new frame window once the user enters a valid email and password (COMMUNITYSYS).  If email and password are not valid than a new frame window should say that User has entered invalid email and password.

This new frame window should display a form:
Enter the name (textfield)
Enter the destination (choicelist)
Enter the city (choicelist)
Salary: 5000-9000 (radio button)  10000-15000 (radio button)
ID is: (textfield)

There are 2 buttons - OK and CLEAR.

Now what should happen, is that in the ID textfield, what should display is the first characters of the user's name, the destination, the city and the salary.  So for example if I enter:

Susan
Faculty
Maryland
10000

The ID textfield should display: SFM10000

ahosang, if the ID textfield can display the first characters of the information in the textfield than it would be excellent but if you can think of a better way of how to do this than I would be very grateful.  The main thing is to make sure that the first characters be displayed as the ID.

Thanks,
susan




Avatar of ahosang
ahosang
Flag of United Kingdom of Great Britain and Northern Ireland image

Just to check, does that mean you no longer require the name textfield?
Actually could you tell me if you want any of the old stuff on the original applet. Tell me if I got it right:
You want just two textfields only: email and password, and if the validation is good then continue as stated above?
Avatar of susanbirnbaum
susanbirnbaum

ASKER

Hi ahosang,
Yes your second comment is correct:

I just need two textfields - email and password for the first applet window and then continue as above, when the user has entered a correct email address and password(COMMUNITYSYS).

Thanks,
susan

ahosang - in the first applet with just the email and password textfields, can you keep the "Welcome" scroller on the top as in the original please.

Thanks,
susan
susan, sorry my personal and work time have been SO busy recently, I have not had a chance to implement this yet. Could you tell me when your deadline is. Also, please compile this and see if it is a starting point:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class plum2 extends Applet implements ActionListener, Runnable {

Frame frame;
Button b;
Button b2;

//scroll text
Font f = new Font("Arial Black", Font.BOLD, 18);
Color col = new Color(204,153,0);
Color back = new Color(249,249,249);
String wel = new String("WELCOME");
Thread runner;
int x;
int stringSize;

GridLayout detgrid=new GridLayout(3,2,5,5);

public void start() {
  if (runner == null) {
     runner = new Thread(this);
     runner.start();
  }
}

public void stop() {
  if (runner != null) {
     runner = null;
  }
}

public void run() {
  Thread thisThread = Thread.currentThread();
  x = 10-stringSize;
  int cont = getSize().width;
  while (runner == thisThread) {
     x = x + 3;
     repaint();
     try {
       Thread.sleep(50);
     } catch (InterruptedException e) {}
     if (x > cont) {
         x = -stringSize;
       }
  }
}

String msg=" ";

//TextField
TextField email,pass;

// Labels
Label passwordLabel, emailLabel;
Label scrollText;

public void init() {
  setLayout(null);

  //scroll text
  setForeground(col);
  setBackground(back);
  FontMetrics fm=getFontMetrics(f);
  stringSize=fm.stringWidth(wel);
  Panel scrollPanel=new Panel();
  scrollPanel.setBounds(0,0,400,50);
  add(scrollPanel);
  scrollPanel.setVisible(false);

  // email textfield
  emailLabel=new Label("E-mail: ", Label.RIGHT);
  email=new TextField(12);

  // password textfield
  passwordLabel=new Label("Password: ", Label.RIGHT);
  pass=new TextField(12);
  pass.setEchoChar('*');

  Panel pChoices=new Panel();
  pChoices.setLayout(detgrid);
  pChoices.add(emailLabel);
  pChoices.add(email);
  pChoices.add(passwordLabel);
  pChoices.add(pass);
 
  pChoices.setBounds(100,100,200,70);
  pChoices.setVisible(true);

  // adding buttons here
  b=new Button("OK");
  b2=new Button("Clear");
  b.addActionListener(this);
  b2.addActionListener(this);
  pChoices.add(b);
  pChoices.add(b2);
  add(pChoices);
}



public void paint(Graphics g) {
  g.setFont(f);
  g.drawString(wel, x, 30);
}

public void actionPerformed(ActionEvent ae) {
  if (ae.getActionCommand().equals("OK")) {
    char c;
    if ((!email.getText().equals(""))&&(Character.isLetter(c=email.getText().charAt(0)))&&
                (pass.getText().equals("COMMUNITYSYS"))&&(email.getText().indexOf("@")!=-1)) {
        if (frame!=null) {
          frame.dispose();
            frame=null;
        }
      frame=new Frame("Results");
        frame.setBounds(100,100,400,400);
        frame.setResizable(false);
      frame.setVisible(true);
      frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
              frame.dispose();
                    frame=null;
            }
        });
        Panel formPanel=new Panel();
        formPanel.setLayout(new GridLayout(5,1,5,5));
        // name label
        Panel namePanel=new Panel();
        Label nameLab=new Label("Enter your name:");
        TextField nameTF=new TextField(20);
        namePanel.add(nameLab);
        namePanel.add(nameTF);
        formPanel.add(namePanel);
        // destination label
        Panel destPanel=new Panel();
        Label destLab=new Label("Enter your destination: ");
        List destList=new List();
        destList.add("faculty");
        destList.add("students");
        destList.add("medicine");
        destPanel.add(destLab);
        destPanel.add(destList);
        formPanel.add(destPanel);
        // City label
        Panel cityPanel=new Panel();
        Label cityLab=new Label("Enter the city");
        List cityList=new List();
        cityList.add("Paris");
        cityList.add("London");
        cityList.add("Milan");
        cityList.add("New York");
        cityPanel.add(cityLab);
        cityPanel.add(cityList);
        formPanel.add(cityPanel);
        // Salary Range
        Panel salaryPanel=new Panel();
        Label salaryLab=new Label("Salary: ");
        CheckboxGroup cbg=new CheckboxGroup();
        Checkbox cb1=new Checkbox("5000-9000",cbg,false);
        Checkbox cb2=new Checkbox("10000-15000",cbg,false);
        salaryPanel.add(salaryLab);
        salaryPanel.add(cb1);
        salaryPanel.add(cb2);
        formPanel.add(salaryPanel);
        
        // ID label
        Panel idPanel=new Panel();
        Label idLab=new Label("ID: ");
        TextField idTF=new TextField(20);
        idPanel.add(idLab);
        idPanel.add(idTF);
        formPanel.add(idPanel);
        frame.add(formPanel);
      } else {
        if (frame!=null) {
          frame.dispose();
            frame=null;
        }
        frame=new Frame("Invalid Data");
      frame.setBounds(100,100,400,400);
        frame.setResizable(false);
      frame.setVisible(true);
      frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
              frame.dispose();
                    frame=null;
            }
        });
        frame.add(new Label("Invalid Data"));
      }
  } else if (ae.getActionCommand().equals("Clear")) {
      // DO SOMETHING HERE
      email.setText("");
      pass.setText("");    
  } else {
        frame.invalidate();
        frame.validate();
  }
}
}

The validation should be good, but the form is not setting the ID yet.
Hello ahosang,

Thank you so much for doing this program in between your busy schedule, I apologize for any inconvenience caused, it's only because your applets work so well! I did compile the program and it's working perectly.

ahosang, I have shown your program to my colleagues and they all say it's really good.  I hope I do not pressure you when I say if it all possible can it be finished by this Monday (actually the staff wanted something for this Friday but I can understand about the ID problem).  We don't mind if you need to create another window or button to extract the first characters for the ID.  Actually we leave this up to your expert knowledge how best it would look.

Thanks you,
susan
ASKER CERTIFIED SOLUTION
Avatar of ahosang
ahosang
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello ahosang,

I'm sorry I couldn't reply asap, our computers had to be reinstalled with some new software and we couldn't get connected to the internet for the past few days. But now everything is fine.  

ahosang, I compiled your program and it's perfect - it's working well and the layout is really nice with the button to display the ID! It's just what we wanted.

You have done so much work for us and we are so grateful for all the time and hard work you have spent making our programs!  You deserve a good grade for all your expertise!

Thanks again,
susan