-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFacePamphlet.java
More file actions
139 lines (124 loc) · 3.84 KB
/
Copy pathFacePamphlet.java
File metadata and controls
139 lines (124 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* File: FacePamphlet.java
* -----------------------
* When it is finished, this program will implement a basic social network
* management system.
*/
import acm.program.*;
import acm.graphics.*;
import acm.util.*;
import java.awt.event.*;
import javax.swing.*;
import acm.graphics.*;
import java.awt.*;
import java.util.*;
public class FacePamphlet extends Program
implements FacePamphletConstants {
/**
* This method has the responsibility for initializing the
* interactors in the application, and taking care of any other
* initialization that needs to be performed.
*/
public void init() {
add(new JLabel("Name"),NORTH);
NText=new JTextField(TEXT_FIELD_SIZE);
NText.addActionListener(this);
add(NText,NORTH);
add(new JButton("Add"),NORTH);
addActionListeners();
add(new JButton("Delete"),NORTH);
add(new JButton("Lookup"),NORTH);
addActionListeners();
//===============UP IS NORTH==========BELOW IS WEST======================
SText=new JTextField(TEXT_FIELD_SIZE);
SText.setActionCommand("Change Status");
SText.addActionListener(this);
add(SText,WEST);
add(new JButton("Change Status"),WEST);
PText=new JTextField(TEXT_FIELD_SIZE);
PText.setActionCommand("Change Picture");
PText.addActionListener(this);
add(PText,WEST);
add(new JButton("Change Picture"),WEST);
FText=new JTextField(TEXT_FIELD_SIZE);
FText.setActionCommand("Add Friend");
FText.addActionListener(this);
add(FText,WEST);
add(new JButton("Add Friend"),WEST);
addActionListeners();
setSize(APPLICATION_WIDTH,APPLICATION_HEIGHT);
Canvas=new FacePamphletCanvas();
add(Canvas);
Data=new FacePamphletDatabase();
}
/**
* This class is responsible for detecting when the buttons are
* clicked or interactors are used, so you will have to add code
* to respond to these actions.
*/
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand()=="Add"){
Data.addProfile(NText.getText());
User=Data.getProfile(NText.getText());
Canvas.displayProfile(User);
}
/* this part is to delete,so we have to find out his friend ,and delete him */
if(e.getActionCommand()=="Delete"){
FacePamphletProfile remover=Data.getProfile(NText.getText());
if(remover!=null){
Iterator<String> it=remover.getFriends();
while(it.hasNext()){
FacePamphletProfile tempmove=Data.getProfile(it.next());
while(!tempmove.removeFriend(NText.getText())){}
}
Canvas.displayProfile(User);
Data.deleteProfile(NText.getText());
if(User.getName()==NText.getText()){
Canvas.removeAll();
}
}
else{
Canvas.showMessage("there is not this user");
}
}
if(e.getActionCommand()=="Lookup"){
if(Data.containsProfile(NText.getText())){
Canvas.displayProfile(Data.getProfile(NText.getText()));
}
else{
Canvas.showMessage("CAN NOT FIND THIS USER");
}
}
//=============UPPER THE LINE IS NORTH==========BELOW THE LINE IS WEST===============
if(e.getActionCommand()=="Change Status"){
User.setStatus(SText.getText());
Canvas.displayProfile(User);
}
if(e.getActionCommand()=="Change Picture"){
User.setImage(PText.getText());
Canvas.displayProfile(User);
}
if(e.getActionCommand()=="Add Friend"){
if(Data.getProfile(FText.getText())!=null){
if(User.addFriend(FText.getText()) ){
Data.getProfile(FText.getText()).addFriend(User.getName());
Canvas.showMessage("You have add"+FText.getText()+"to be your friend");
Canvas.displayProfile(User);
}
else{
Canvas.showMessage("you have this friend");
}
}
else{
Canvas.showMessage("Addtion fail");
}
}
}
private JTextField NText;
private JTextField SText;
private JTextField PText;
private JTextField FText;
private FacePamphletCanvas Canvas;
private FacePamphletDatabase Data;
private FacePamphletProfile User;
}