-
Notifications
You must be signed in to change notification settings - Fork 0
/
ley.java
197 lines (172 loc) · 5.39 KB
/
ley.java
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import org.jivesoftware.smack.roster.RosterEntry;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.filetransfer.FileTransferListener;
import org.jivesoftware.smackx.filetransfer.FileTransferManager;
import org.jivesoftware.smackx.filetransfer.FileTransferRequest;
import org.jivesoftware.smackx.filetransfer.IncomingFileTransfer;
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer;
@SuppressWarnings("serial")
public class ley extends JFrame
{
public static JFrame frame;
JButton connect;
public static XMPPConnection connection;
Collection<RosterEntry> list;
public static ArrayList<String> buttons;
public ley()
{
set_layout_login_page();
}
void set_layout_login_page()
{
frame = new JFrame("LOGIN");
final JPasswordField pass;
final JTextField u_name;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
final JPanel main = new JPanel();
JButton login = new JButton();
Container pane = frame.getContentPane();
pane.setLayout(new BorderLayout());
main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));
panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS));
panel1.add(new JLabel(" Username "));
u_name = new JTextField("", 15);
panel1.add(u_name);
panel1.add(new JLabel(" "));
main.add(new JLabel(" "));
main.add(panel1);
main.add(new JLabel(" "));
panel2.add(new JPanel());
pass = new JPasswordField("", 15);
pass.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try
{
String uname = u_name.getText();
if(uname.indexOf("@gmail.com") < 0){
uname += "@gmail.com";
}
String pas = Arrays.toString(pass.getPassword());
main.setVisible(false);
frame.removeAll();
frame.setTitle("BUDDY LIST");
new retrieve_roster(uname, pass);
}catch(XMPPException e){
Logger.getLogger(ley.class.getName()).log(Level.SEVERE, null, e);
}
}
});
panel2.add(pass);
panel2.add(new JLabel(" "));
main.add(panel2);
main.add(new JLabel(" "));
login = new JButton("Login");
login.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent event)
{
try{
String uname = u_name.getText();
if(uname.indexOf("@gmail.com") < 0){
uname += "@gmail.com";
}
String pas = Arrays.toString(pass.getPassword());
main.setVisible(false);
frame.removeAll();
frame.setTitle("Buddy List");
new retrieve_roster(uname, pass);
}catch(XMPPException e){
Logger.getLogger(ley.class.getName()).log(Level.SEVERE, null, e);
}
}
});
main.add(login);
pane.add(main, BorderLayout.NORTH);
frame.setVisible(true);
}
public static void main(String[] args)
{
new ley();
}
//Below this are two classes related to file transfer. Not implemented properly. Redesign it later...
public class receive_file implements Runnable
{
public receive_file()
{
new Thread(this).start();
}
@override
public void run()
{
FileTransferManager manager = new FileTransferManager(connection);
manager.addFileTransferListener(new FileTransferListener(){
public void fileTransferRequest(FileTransferRequest request){
try{
int ret = JOptionPane.showConfirmDialog(null, request.getRequestor() + "sending a file named" + request.getFileName());
System.out.println("Returned Value: " + ret);
if(ret == 0){
System.out.println("Returned Value: " + ret);
IncomingFileTransfer transfer = request.accept();
transfer.receiveFile(new File("received_file"));
System.out.println("File Received");
}
}
catch(XMPPException e){
e.printStackTrace();
}
}
});
}
}
public class sendfileto implements ActionListener
{
@override
public void actionPerformed(ActionEvent e)
{
String file_path = JOptionPane.showInputDialog("Enter the path of the file");
String receiver = e.getActionCommand();
System.out.println("in sendfileto " + receiver);
FileTransferManager mgr = new FileTransferManager(connection);
OutgoingFileTransfer transfer = mgr.createOutgoingFileTransfer(receiver);
File file = new File(file_path);
try
{
transfer.sendFile(file, "file");
while(!transfer.isDone())
{
System.out.println(transfer.getProgress() + " is done!");
}
System.out.println("Loop broken " + transfer.getProgress() + " is done!");
}
catch(Exception ex)
{
Logger.getLogger(ley.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}