6 Replies - 804 Views - Last Post: 06 July 2008 - 07:49 PM Rate Topic: -----

#1 rphotos  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 06-July 08

Employee Applet

Post icon  Posted 06 July 2008 - 04:59 PM

okay = I am totaly lost now, I thought I had it. I am trying to make an Applet using two parallel arrays using 5 names and 5 job titles. I am trying to make it so if you pick a name you get the job title or vise versa. I made one all ready to divide numbers but the parallel array thing has me stumped. :crazy: Here is what I have done so far, I will countinue to work on it but if anyone can offer help I would appreciate it.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class EmployeeTitle3 extends JApplet implements ActionListener
{
	Container con = getContentPane();
	JLabel greeting = new JLabel("Emplyoyees are: John,Allan,Henry,David,Chris and the jobs are Manager,Asst_Mgr,CEO, EEO_Mgr, Fin_Mgr ");
	Font bigFont = new Font("Times Roman", Font.ITALIC, 24);
	JLabel Label = new JLabel("Please enter a name or job: ");
	JTextField firstField = new JTextField("",10);
	JButton viewButton = new JButton(" Display match");
	FlowLayout flow = new FlowLayout();
	public void init()
	final int NUMBER_OF_NAMES = 5;
	String [] validNames = {"John", "Allan", "Henry", "David", "Chris"};
	String [] title = {"Manager", "Asst_Mgr", "CEO", "EEO_Mgr", "Fin_Mgr"};
	String strItem;
	double vaildNames;
	double empName=vaildNames;
	boolean validName = false;
	{
	greeting.setFont(bigFont);
		con.add(greeting);
		con.setLayout(flow);
		con.add(firstLabel);
		con.add(lastLabel);
		con.add(viewButton);
		viewButton.addActionListener(this);
		firstField.requestFocus();
		}
		public void actionPerformed(ActionEvent thisEvent)
		{
		String firstName = firstField.getText();
		int x;
		for(x = 0; x < validNames.lenght; x++)
 		{
		if(strItem.equals(validNames[x]))
		break;
		}
		if(x == validNames.length) 
		greeting.setText("Sorry - invalid item entered");
		else
		greeting.setText(strItem + " is the " + title[x]);
		}
		}


This post has been edited by rphotos: 06 July 2008 - 07:21 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Employee Applet

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: Employee Applet

Posted 06 July 2008 - 05:41 PM

Problem in your posting
We are missing at least half of your code
Was This Post Helpful? 1
  • +
  • -

#3 rphotos  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 06-July 08

Re: Employee Applet

Posted 06 July 2008 - 05:50 PM

This is where I am at right now - I am not sure what else to do, I tried converting my last project using what I know of parallel arrays.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: Employee Applet

Posted 06 July 2008 - 06:27 PM

View Postrphotos, on 6 Jul, 2008 - 05:50 PM, said:

This is where I am at right now - I am not sure what else to do, I tried converting my last project using what I know of parallel arrays.

Misunderstanding... we cannot see all your code (the code in your first post got truncated).. you'll have to post it again
Was This Post Helpful? 0
  • +
  • -

#5 rphotos  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 06-July 08

Re: Employee Applet

Posted 06 July 2008 - 06:48 PM

okay - will ty again

 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class EmployeeTitle3 extends JApplet implements ActionListener
{
	Container con = getContentPane();
	JLabel greeting = new JLabel("Emplyoyees are: John,Allan,Henry,David,Chris and the jobs are Manager,Asst_Mgr,CEO, EEO_Mgr, Fin_Mgr ");
	Font bigFont = new Font("Times Roman", Font.ITALIC, 24);
	JLabel Label = new JLabel("Please enter a name or job: ");
	JTextField firstField = new JTextField("",10);
	JButton viewButton = new JButton(" Display match");
	FlowLayout flow = new FlowLayout();
	public void init()
	final int NUMBER_OF_NAMES = 5;
	String [] validNames = {"John", "Allan", "Henry", "David", "Chris"};
	String [] title = {"Manager", "Asst_Mgr", "CEO", "EEO_Mgr", "Fin_Mgr"};
	String strItem;
	double vaildNames;
	double empName=vaildNames;
	boolean validName = false;
	{
	greeting.setFont(bigFont);
		con.add(greeting);
		con.setLayout(flow);
		con.add(firstLabel);
		con.add(lastLabel);
		con.add(viewButton);
		viewButton.addActionListener(this);
		firstField.requestFocus();
		}
		public void actionPerformed(ActionEvent thisEvent)
		{
		String firstName = firstField.getText();
		int x;
		for(x = 0; x < validNames.lenght; x++)
 		{
		if(strItem.equals(validNames[x]))
		break;
		}
		if(x == validNames.length) 
		greeting.setText("Sorry - invalid item entered");
		else
		greeting.setText(strItem + " is the " + title[x]);
		}
		}



just in case it did not work - here it is in text form

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class EmployeeTitle3 extends JApplet implements ActionListener
{
Container con = getContentPane();
JLabel greeting = new JLabel("Emplyoyees are: John,Allan,Henry,David,Chris and the jobs are Manager,Asst_Mgr,CEO, EEO_Mgr, Fin_Mgr ");
Font bigFont = new Font("Times Roman", Font.ITALIC, 24);
JLabel Label = new JLabel("Please enter a name or job: ");
JTextField firstField = new JTextField("",10);
JButton viewButton = new JButton(" Display match");
FlowLayout flow = new FlowLayout();
public void init()
final int NUMBER_OF_NAMES = 5;
String [] validNames = {"John", "Allan", "Henry", "David", "Chris"};
String [] title = {"Manager", "Asst_Mgr", "CEO", "EEO_Mgr", "Fin_Mgr"};
String strItem;
double vaildNames;
double empName=vaildNames;
boolean validName = false;
{
greeting.setFont(bigFont);
con.add(greeting);
con.setLayout(flow);
con.add(firstLabel);
con.add(lastLabel);
con.add(viewButton);
viewButton.addActionListener(this);
firstField.requestFocus();
}
public void actionPerformed(ActionEvent thisEvent)
{
String firstName = firstField.getText();
int x;
for(x = 0; x < validNames.lenght; x++)
{
if(strItem.equals(validNames[x]))
break;
}
if(x == validNames.length)
greeting.setText("Sorry - invalid item entered");
else
greeting.setText(strItem + " is the " + title[x]);
}
}

This post has been edited by rphotos: 06 July 2008 - 06:50 PM

Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: Employee Applet

Posted 06 July 2008 - 07:24 PM

firstLabel, lastLabel are not defined
validNames.length is misspelled
strItem is not defined in ActionPerformed

public void init() .... should be
public void init() {
... some code here
}

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class EmployeeTitle3 extends JApplet implements ActionListener
{
	Container con = getContentPane();
	JLabel greeting = new JLabel("Emplyoyees are: John,Allan,Henry,David,Chris and the jobs are Manager,Asst_Mgr,CEO, EEO_Mgr, Fin_Mgr ");
	Font bigFont = new Font("Times Roman", Font.ITALIC, 24);
	JLabel Label = new JLabel("Please enter a name or job: ");
	JTextField firstField = new JTextField("",10);
	JButton viewButton = new JButton(" Display match");
	FlowLayout flow = new FlowLayout();
	
	final int NUMBER_OF_NAMES = 5;
	String [] validNames = {"John", "Allan", "Henry", "David", "Chris"};
	String [] title = {"Manager", "Asst_Mgr", "CEO", "EEO_Mgr", "Fin_Mgr"};
	String strItem;
	double vaildNames;
	double empName=vaildNames;
	boolean validName = false;
	
	public void init()
	{
		greeting.setFont(bigFont);
		con.add(greeting);
		con.setLayout(flow);
		con.add(firstLabel);
		con.add(lastLabel);
		con.add(viewButton);
		viewButton.addActionListener(this);
		firstField.requestFocus();
	}
	public void actionPerformed(ActionEvent thisEvent)
	{
		String firstName = firstField.getText();
		int x;
		for(x = 0; x < validNames.length; x++)
		{
			if(strItem.equals(validNames[x]))
				break;
		}
		if(x == validNames.length) 
			greeting.setText("Sorry - invalid item entered");
		else
			greeting.setText(strItem + " is the " + title[x]);
	}
}


Was This Post Helpful? 0
  • +
  • -

#7 rphotos  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 06-July 08

Re: Employee Applet

Posted 06 July 2008 - 07:49 PM

Thanks PBL - I am lost when it comes to Arrays
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1