Solved

Urgently need ahosang...

Posted on 2001-08-03
8
233 Views
Last Modified: 2010-03-31
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




0
Comment
Question by:susanbirnbaum
  • 4
  • 4
8 Comments
 
LVL 12

Expert Comment

by:ahosang
ID: 6350671
Just to check, does that mean you no longer require the name textfield?
0
 
LVL 12

Expert Comment

by:ahosang
ID: 6350741
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?
0
 

Author Comment

by:susanbirnbaum
ID: 6350828
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

0
 

Author Comment

by:susanbirnbaum
ID: 6350886
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
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Expert Comment

by:ahosang
ID: 6365357
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.
0
 

Author Comment

by:susanbirnbaum
ID: 6366655
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
0
 
LVL 12

Accepted Solution

by:
ahosang earned 200 total points
ID: 6370342
Something like this. You can play with the layout:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class plum2 extends Applet implements ActionListener, Runnable {

myFrame frame;
Frame frame2;
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 (frame2!=null) {
          frame2.dispose();
            frame2=null;
        }
      frame=new myFrame("Results");
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
              frame.dispose();
                    frame=null;
            }
        });
      } else {
        if (frame!=null) {
          frame.dispose();
            frame=null;
        }
        frame2=new Frame("Invalid Data");
      frame2.setBounds(100,100,400,400);
        frame2.setResizable(false);
      frame2.setVisible(true);
      frame2.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
              frame2.dispose();
                    frame2=null;
            }
        });
        frame2.add(new Label("Invalid Data",Label.CENTER));
      }
  } else if (ae.getActionCommand().equals("Clear")) {
      // DO SOMETHING HERE
      email.setText("");
      pass.setText("");    
  } else if (ae.getActionCommand().equals("Examine ID")) {
     
  } else {
        frame.invalidate();
        frame.validate();
  }
}

class myFrame extends java.awt.Frame implements ActionListener {
  TextField nameTF,idTF;
  List destList, cityList;
  CheckboxGroup cbg;
 
 
  public myFrame(String title) {
      super(title);
        setBounds(100,100,400,400);
        setResizable(false);
      setVisible(true);
     
        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:");
        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: ");
        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");
        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: ");
        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();
        Button idButton=new Button("Examine ID");
        idButton.addActionListener(this);
        Label idLab=new Label("ID: ");
        idTF=new TextField(20);
        idPanel.add(idButton);
        idPanel.add(idLab);
        idPanel.add(idTF);
        formPanel.add(idPanel);
        add(formPanel);
  }
  public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equals("Examine ID")) {
        if ((nameTF.getText()!="")&&(destList.getSelectedItem()!=null)&&(cityList.getSelectedItem()!=null)&&(cbg.getSelectedCheckbox()!=null)) {
          String salRange=cbg.getSelectedCheckbox().getLabel();
            String ID=nameTF.getText().substring(0,1)+destList.getSelectedItem().substring(0,1)+
                    cityList.getSelectedItem().substring(0,1)+salRange.substring(0,salRange.indexOf("-"));
            idTF.setText(ID);
        }
      }
  }
}

}

Remember when compiling you will get an additional class file - plum2$myFrame.class
Make sure you put that in the same directory as the plum2.class
0
 

Author Comment

by:susanbirnbaum
ID: 6385113
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



0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now