forked from NAYEMA26/Recursive_Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeedback
86 lines (70 loc) · 2.91 KB
/
Feedback
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
package notepad;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class Feedback extends JFrame implements ActionListener {
private JTextField txtapi, txtmsg, txtsender, txtnumber;
public Feedback() {
setTitle("Send SMS");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(5, 2));
JLabel labelApiKey = new JLabel("API Key:");
txtapi = new JTextField();
JLabel lblMessage = new JLabel("Message:");
txtmsg = new JTextField();
JLabel lblSender = new JLabel("Sender:");
txtsender = new JTextField();
JLabel lblNumber = new JLabel("Recipient Number:");
txtnumber = new JTextField();
JButton btnSend = new JButton("Send");
btnSend.addActionListener(this);
panel.add(labelApiKey);
panel.add(txtapi);
panel.add(lblMessage);
panel.add(txtmsg);
panel.add(lblSender);
panel.add(txtsender);
panel.add(lblNumber);
panel.add(txtnumber);
panel.add(new JLabel());
panel.add(btnSend);
add(panel);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Send")) {
try {
String apiKey = "apikey=" + URLEncoder.encode(txtapi.getText(), "UTF-8");
String message = "&message=" + URLEncoder.encode(txtmsg.getText(), "UTF-8");
String sender = "&sender=" + URLEncoder.encode(txtsender.getText(), "UTF-8");
String numbers = "&numbers=" + URLEncoder.encode(txtnumber.getText(), "UTF-8");
HttpURLConnection conn = (HttpURLConnection) new URL("https://api.txtlocal.com/send/?").openConnection();
String data = apiKey + numbers + message + sender;
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Length", Integer.toString(data.length()));
conn.getOutputStream().write(data.getBytes("UTF-8"));
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuffer stringBuffer = new StringBuffer();
String line;
while ((line = rd.readLine()) != null) {
JOptionPane.showMessageDialog(null, "Message sent successfully.");
}
rd.close();
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage());
}
}
}
public static void main(String[] args) {
new Feedback();
}
}