DOC PREVIEW
Duke CPS 004 - Director. java

This preview shows page 1-2-21-22 out of 22 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Directory.javaDirectory.java is a program whose purpose is to check membership within a group. The three basic operations of Directory.java areenter – adds a name, id pair to the groupremove – removes a name from the group and its corresponding idlookup – determines if a name is in the group. If the name is in the group, then the id field is set with the user's id and the message field indicates that the name is in the group. Otherwise, the message field indicates the name is not in the group.Your job is to fill in the missing code in Directory.java. The comments, method and variable names should give you enough context to be able to fill in the blanks. You only need to fill in where there are blanks.Directory.javaimport javax.swing.*;import java.awt.*;import java.awt.event.*;import java.util.*;/* * Created on Feb 28, 2004 *//** * @author Jam Jenkins * * This class simulates a directory of students and ids */public class Directory extends JApplet implements ActionListener {private JFrame frame;private JButton removeButton, enterButton, lookupButton, quitButton;private JLabel nameLabel, idLabel, messageLabel;private JTextField nameField, idField, messageField;private HashMap members;public Directory(){super();makeComponents();layoutComponents();members=new HashMap();}Directory.java/** initialize all of the component instance * variables and add this as an * ActionListener to all JButtons*/private void makeComponents(){frame=new JFrame("Access Control");removeButton=new JButton("remove");removeButton.addActionListener(this); ; ; ; ; ; ;nameLabel=new JLabel("Name:"); ; ;nameField=new JTextField(20); ; ;}Directory.java/**put all components in the JFrame's container*/private void layoutComponents(){Container container=frame.getContentPane();container.setLayout( );container.add( );container.add( );frame.pack();}/** * @return the Jpanel with all the JLabels and JTextFields */private JPanel getMiddlePanel(){ ;panel.add(nameLabel);panel.add(nameField);panel.add(idLabel);panel.add(idField);panel.add(messageLabel);panel.add(messageField);return panel;}Directory.java/** * @return the JPanel with all the JButtons */private JPanel getButtonPanel(){JPanel panel=new JPanel(new GridLayout(1, 4));panel.add( );panel.add( );panel.add( );panel.add( );return panel;}Directory.java/** * removes a user to members by getting input * from nameField. If the user existed, the * messageField indicates the user was removed, * otherwise the messageField indicates that no * such user was a member */private void remove(){String name=nameField.getText();if(members.containsKey(name)){members.remove(name);messageField.setText(name+" removed from members.");}else{messageField.setText(name+" is not a member.");}}/** * adds a user to members by getting input * from nameField and idField */private void enter(){String name=nameField.getText();String id=idField.getText();members.put(name, id);messageField.setText(name+" added as a member.");nameField.setText("");idField.setText("");}/** * looks up a user by name and outputs the * user id in the idField (if found) and * indicates whether the user is or is not * a member in the messageField */private void lookup(){String name=nameField.getText();if(members.containsKey(name)){String id=(String)members.get(name);idField.setText(id);messageField.setText(name+" is a member.");}else{messageField.setText(name+" is not a member.");}}/** * quits the program */private void quit(){frame.setVisible(false);frame.dispose();System.exit(0);}Directory.javapublic void actionPerformed(ActionEvent e) {Object cause=e.getSource();if(cause== ){//removes a user and corresponding idremove();}else if(cause==enterButton){//adds a user and corresponding id ;}else if( ){//looks up a user and corresponding id ;}else if( ){//quits the program ;}}Directory.javapublic void init(){frame.setVisible(true);}public static void main(String[] args) {Directory directory=new Directory();directory.init();}}TopTenYour mission is to fill in the missing code in TopTen.java, TopTenPanel.java, and TopTenTest.java. The comments, method and variable names should give you enough context to be able to fill in the blanks. You only need to fill in where there are blanks. A description of each class is given to the right.TopTen.java – this class keeps the scores in an array of doubles sorted least to greatest. It extends Observable and is the model.TopTenPanel – this class displays the scores in a Jpanel which it extends. This class is the view.TopTenTest – this class is the controller and it connects the model (TopTen) and the view (TopTenPanel) in order to test them.TopTen.javaimport java.util.*;/** * @author Jam Jenkins * * This class keeps a list of the top ten scores. */public class TopTen extends Observable{/**scores is ordered in ascending order*/double[] scores; public TopTen(){//initialize score to hold 10 doubles ;}TopTen.java/** * add a score if it ranks in the top ten * @param s the score to add */public void registerScore(double s){//remember that score is sorted least to greatestif( )//score is better than the lowest score{scores[0]=s;Arrays.sort(scores);setChanged();notifyObservers();}}TopTen.java /** * get a score from the top ten * @param rank the position in the top ten list * with 1 being the highest and 10 being the lowest * @return the score */public double getScore(int rank){//score is sorted least to greatest//think about how the rank relates to the index in the arrayreturn ;}}TicTacToe.javaimport java.awt.*;import javax.swing.*;import java.util.*;/** * @author Jam Jenkins * * Displays the scores in a JPanel */public class TopTenPanel extends JPanelimplements Observer{/**JLabels with the numbers 1-10*/ private JLabel[] ranks;/**the numeric scores for the top ten*/private JLabel[] scores; public TopTenPanel(){super();makeComponents();layoutComponents();}TopTenPanel.javaprivate void makeComponents(){ranks=new JLabel[10];scores=new JLabel[10];for(int i=0; ; i++){ranks[i]=new JLabel(""+(i+1));scores[i]=new JLabel("none");}} private void layoutComponents(){setLayout(new GridLayout(10, 2));for( ;


View Full Document

Duke CPS 004 - Director. java

Documents in this Course
Lecture

Lecture

18 pages

Chapter 7

Chapter 7

18 pages

Chapter 9

Chapter 9

15 pages

Java 1

Java 1

24 pages

Java 3

Java 3

11 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

28 pages

Chap 2

Chap 2

16 pages

Graphics

Graphics

20 pages

Lecture

Lecture

12 pages

HTML

HTML

16 pages

Java 1

Java 1

6 pages

Chapter 4

Chapter 4

16 pages

The Plan

The Plan

25 pages

Lecture

Lecture

16 pages

Chapter 6

Chapter 6

21 pages

Lecture

Lecture

18 pages

Lecture

Lecture

23 pages

Lecture

Lecture

16 pages

Lecture

Lecture

19 pages

Lecture

Lecture

12 pages

Lecture

Lecture

5 pages

Lecture

Lecture

26 pages

Lecture

Lecture

16 pages

Chapter 7

Chapter 7

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

4 pages

Lecture

Lecture

4 pages

Lecture

Lecture

8 pages

Lecture

Lecture

4 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

32 pages

Java

Java

4 pages

CompSci 4

CompSci 4

18 pages

Lecture

Lecture

26 pages

CompSci 4

CompSci 4

12 pages

HTML

HTML

17 pages

Lecture

Lecture

16 pages

Chapter 5

Chapter 5

22 pages

Lecture

Lecture

4 pages

Chapter 4

Chapter 4

10 pages

Chapter 2

Chapter 2

15 pages

Chapter 8

Chapter 8

14 pages

Lecture

Lecture

15 pages

Load more
Download Director. java
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Director. java and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Director. java 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?