Repository navigation
Expand file tree
/
Copy pathFrame1.java
More file actions
100 lines (81 loc) · 2.76 KB
/
Copy pathFrame1.java
File metadata and controls
100 lines (81 loc) · 2.76 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
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
public class Frame1 extends JFrame implements ActionListener {
private JPanel panelSouth, panelWest, panelEast, panelCenter, panelNorth;
private JButton send, addContact, removeContact, decrypt;
private JTextField input;
private JTextArea convo;
private JLabel message;
private JList contacts;
ArrayList<String> contactList = new ArrayList<String>();
public Frame1() {
panelSouth = new JPanel();
panelEast = new JPanel();
panelWest = new JPanel();
panelCenter = new JPanel();
panelNorth = new JPanel();
contactList.add("Peter");
contactList.add("Reid");
contactList.add("Jonny");
contactList.add("Ryan");
//create south panel
panelSouth.setLayout(new FlowLayout());
message = new JLabel("Enter a message:");
panelSouth.add(message);
input = new JTextField(20);
panelSouth.add(input);
send = new JButton("Send");
panelSouth.add(send);
send.addActionListener(this);
decrypt = new JButton ("Decrypt Message");
panelSouth.add(decrypt);
//create center panel
panelCenter.setLayout(new FlowLayout());
JTextArea convo = new JTextArea("New Convo\n", 30, 35);
convo.setLineWrap(true);
convo.setWrapStyleWord(true);
panelCenter.add(convo);
//create west panel
panelWest.setLayout(new BorderLayout());
addContact = new JButton ("Add Contact");
panelWest.add(addContact, BorderLayout.NORTH);
addContact.addActionListener(this);
contacts = new JList(contactList.toArray());
//contacts.addActionListener(this);
panelWest.add(contacts, BorderLayout.CENTER);
removeContact = new JButton ("Remove Contact");
panelWest.add(removeContact, BorderLayout.SOUTH);
add(panelSouth, BorderLayout.SOUTH);
add(panelCenter, BorderLayout.CENTER);
add(panelWest, BorderLayout.WEST);
setTitle("Messenger");
setSize(655,500);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==send){
String newMessage = input.getText();
convo.append(newMessage);
input.setText("");
}
else if(e.getSource()==addContact){
//prompts user to input a new name and IP
String name = JOptionPane.showInputDialog(null, "Enter a name:");
String IP = JOptionPane.showInputDialog(null, "Enter the IP:");
contactList.add(name);
}
else if(e.getSource()==decrypt){
}
else if(e.getSource()==removeContact){
}
}
public static void main(String[] args) {
Frame1 fr = new Frame1();
}
}