Skip to content

Commit 580b221

Browse files
committed
first commit
0 parents  commit 580b221

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2002
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# javaChatFramework

bin/javachat/JavaChat$1.class

822 Bytes
Binary file not shown.

bin/javachat/JavaChat$2.class

685 Bytes
Binary file not shown.

bin/javachat/JavaChat.class

4.44 KB
Binary file not shown.

bin/javachat/network/Client.class

3.53 KB
Binary file not shown.
3.14 KB
Binary file not shown.
2.16 KB
Binary file not shown.

bin/javachat/network/Server.class

4.02 KB
Binary file not shown.
1.63 KB
Binary file not shown.
1.21 KB
Binary file not shown.
Binary file not shown.
1.98 KB
Binary file not shown.
2.51 KB
Binary file not shown.

bin/javachat/network/util/UPnP.class

2.26 KB
Binary file not shown.

bin/javachat/ui/ChatProvider.class

168 Bytes
Binary file not shown.

bin/javachat/ui/ChatWindow$1.class

812 Bytes
Binary file not shown.

bin/javachat/ui/ChatWindow$10.class

771 Bytes
Binary file not shown.

bin/javachat/ui/ChatWindow$11.class

771 Bytes
Binary file not shown.

bin/javachat/ui/ChatWindow$12.class

727 Bytes
Binary file not shown.

bin/javachat/ui/ChatWindow$13.class

771 Bytes
Binary file not shown.

bin/javachat/ui/ChatWindow$14.class

1.25 KB
Binary file not shown.

bin/javachat/ui/ChatWindow$2.class

769 Bytes
Binary file not shown.

bin/javachat/ui/ChatWindow$3.class

769 Bytes
Binary file not shown.

bin/javachat/ui/ChatWindow$4.class

1.19 KB
Binary file not shown.

bin/javachat/ui/ChatWindow$5.class

1.36 KB
Binary file not shown.

bin/javachat/ui/ChatWindow$6.class

1.35 KB
Binary file not shown.

bin/javachat/ui/ChatWindow$7.class

793 Bytes
Binary file not shown.

bin/javachat/ui/ChatWindow$8.class

795 Bytes
Binary file not shown.

bin/javachat/ui/ChatWindow$9.class

769 Bytes
Binary file not shown.

bin/javachat/ui/ChatWindow.class

14.8 KB
Binary file not shown.

bin/javachat/ui/ChatWindow.form

+205
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
4+
<NonVisualComponents>
5+
<Component class="javax.swing.ButtonGroup" name="buttonGroupModeType">
6+
</Component>
7+
</NonVisualComponents>
8+
<Properties>
9+
<Property name="defaultCloseOperation" type="int" value="3"/>
10+
</Properties>
11+
<SyntheticProperties>
12+
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
13+
</SyntheticProperties>
14+
<AuxValues>
15+
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
16+
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
17+
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
18+
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
19+
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
20+
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
21+
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
22+
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
23+
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
24+
</AuxValues>
25+
26+
<Layout>
27+
<DimensionLayout dim="0">
28+
<Group type="103" groupAlignment="0" attributes="0">
29+
<Component id="jScrollPane1" max="32767" attributes="0"/>
30+
<Group type="102" alignment="0" attributes="0">
31+
<Component id="jTextFieldMessage" max="32767" attributes="0"/>
32+
<EmptySpace max="-2" attributes="0"/>
33+
<Component id="jButtonSend" min="-2" max="-2" attributes="0"/>
34+
<EmptySpace max="-2" attributes="0"/>
35+
<Component id="jButtonClear" min="-2" max="-2" attributes="0"/>
36+
</Group>
37+
<Group type="102" alignment="1" attributes="0">
38+
<Group type="103" groupAlignment="1" attributes="0">
39+
<Group type="102" alignment="0" attributes="0">
40+
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
41+
<EmptySpace max="-2" attributes="0"/>
42+
<Component id="jTextFieldName" max="32767" attributes="0"/>
43+
</Group>
44+
<Group type="102" alignment="0" attributes="0">
45+
<Component id="jRadioButtonServer" min="-2" max="-2" attributes="0"/>
46+
<EmptySpace max="-2" attributes="0"/>
47+
<Component id="jRadioButtonClient" min="-2" max="-2" attributes="0"/>
48+
<EmptySpace pref="255" max="32767" attributes="0"/>
49+
<Component id="jLabelHost" min="-2" max="-2" attributes="0"/>
50+
<EmptySpace max="-2" attributes="0"/>
51+
<Component id="jTextFieldHostname" min="-2" pref="221" max="-2" attributes="0"/>
52+
<EmptySpace max="-2" attributes="0"/>
53+
<Component id="jLabelPort" min="-2" max="-2" attributes="0"/>
54+
<EmptySpace max="-2" attributes="0"/>
55+
<Component id="jTextFieldPort" min="-2" pref="76" max="-2" attributes="0"/>
56+
</Group>
57+
</Group>
58+
<EmptySpace max="-2" attributes="0"/>
59+
<Group type="103" groupAlignment="0" max="-2" attributes="0">
60+
<Component id="jButtonUpdateName" max="32767" attributes="0"/>
61+
<Component id="jToggleButtonOnline" max="32767" attributes="0"/>
62+
</Group>
63+
</Group>
64+
</Group>
65+
</DimensionLayout>
66+
<DimensionLayout dim="1">
67+
<Group type="103" groupAlignment="0" attributes="0">
68+
<Group type="102" alignment="0" attributes="0">
69+
<Group type="103" groupAlignment="3" attributes="0">
70+
<Component id="jRadioButtonServer" alignment="3" min="-2" max="-2" attributes="0"/>
71+
<Component id="jRadioButtonClient" alignment="3" min="-2" max="-2" attributes="0"/>
72+
<Component id="jToggleButtonOnline" alignment="3" min="-2" max="-2" attributes="0"/>
73+
<Component id="jTextFieldHostname" alignment="3" min="-2" max="-2" attributes="0"/>
74+
<Component id="jLabelHost" alignment="3" min="-2" max="-2" attributes="0"/>
75+
<Component id="jLabelPort" alignment="3" min="-2" max="-2" attributes="0"/>
76+
<Component id="jTextFieldPort" alignment="3" min="-2" max="-2" attributes="0"/>
77+
</Group>
78+
<EmptySpace max="-2" attributes="0"/>
79+
<Group type="103" groupAlignment="3" attributes="0">
80+
<Component id="jTextFieldName" alignment="3" min="-2" max="-2" attributes="0"/>
81+
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
82+
<Component id="jButtonUpdateName" alignment="3" min="-2" max="-2" attributes="0"/>
83+
</Group>
84+
<EmptySpace max="-2" attributes="0"/>
85+
<Component id="jScrollPane1" pref="433" max="32767" attributes="0"/>
86+
<EmptySpace max="-2" attributes="0"/>
87+
<Group type="103" groupAlignment="3" attributes="0">
88+
<Component id="jTextFieldMessage" alignment="3" min="-2" max="-2" attributes="0"/>
89+
<Component id="jButtonSend" alignment="3" min="-2" max="-2" attributes="0"/>
90+
<Component id="jButtonClear" alignment="3" min="-2" max="-2" attributes="0"/>
91+
</Group>
92+
</Group>
93+
</Group>
94+
</DimensionLayout>
95+
</Layout>
96+
<SubComponents>
97+
<Component class="javax.swing.JRadioButton" name="jRadioButtonServer">
98+
<Properties>
99+
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
100+
<ComponentRef name="buttonGroupModeType"/>
101+
</Property>
102+
<Property name="text" type="java.lang.String" value="Server"/>
103+
</Properties>
104+
<Events>
105+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jRadioButtonServerActionPerformed"/>
106+
</Events>
107+
</Component>
108+
<Component class="javax.swing.JRadioButton" name="jRadioButtonClient">
109+
<Properties>
110+
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
111+
<ComponentRef name="buttonGroupModeType"/>
112+
</Property>
113+
<Property name="selected" type="boolean" value="true"/>
114+
<Property name="text" type="java.lang.String" value="Client"/>
115+
</Properties>
116+
<Events>
117+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jRadioButtonClientActionPerformed"/>
118+
</Events>
119+
</Component>
120+
<Component class="javax.swing.JLabel" name="jLabelHost">
121+
<Properties>
122+
<Property name="text" type="java.lang.String" value="Host:"/>
123+
</Properties>
124+
</Component>
125+
<Component class="javax.swing.JTextField" name="jTextFieldHostname">
126+
<Properties>
127+
<Property name="text" type="java.lang.String" value="localhost"/>
128+
</Properties>
129+
</Component>
130+
<Component class="javax.swing.JLabel" name="jLabelPort">
131+
<Properties>
132+
<Property name="text" type="java.lang.String" value="Port:"/>
133+
</Properties>
134+
</Component>
135+
<Component class="javax.swing.JTextField" name="jTextFieldPort">
136+
<Properties>
137+
<Property name="text" type="java.lang.String" value="12345"/>
138+
</Properties>
139+
</Component>
140+
<Component class="javax.swing.JToggleButton" name="jToggleButtonOnline">
141+
<Properties>
142+
<Property name="text" type="java.lang.String" value="Connect"/>
143+
</Properties>
144+
<Events>
145+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jToggleButtonOnlineActionPerformed"/>
146+
</Events>
147+
</Component>
148+
<Component class="javax.swing.JTextField" name="jTextFieldMessage">
149+
<Events>
150+
<EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="jTextFieldMessageKeyTyped"/>
151+
</Events>
152+
</Component>
153+
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
154+
<AuxValues>
155+
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
156+
</AuxValues>
157+
158+
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
159+
<SubComponents>
160+
<Component class="javax.swing.JTextArea" name="jTextAreaChat">
161+
<Properties>
162+
<Property name="columns" type="int" value="20"/>
163+
<Property name="editable" type="boolean" value="false"/>
164+
<Property name="rows" type="int" value="5"/>
165+
</Properties>
166+
</Component>
167+
</SubComponents>
168+
</Container>
169+
<Component class="javax.swing.JButton" name="jButtonSend">
170+
<Properties>
171+
<Property name="text" type="java.lang.String" value="Send"/>
172+
</Properties>
173+
<Events>
174+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButtonSendActionPerformed"/>
175+
</Events>
176+
</Component>
177+
<Component class="javax.swing.JTextField" name="jTextFieldName">
178+
<Properties>
179+
<Property name="text" type="java.lang.String" value="Unknown"/>
180+
</Properties>
181+
</Component>
182+
<Component class="javax.swing.JLabel" name="jLabel1">
183+
<Properties>
184+
<Property name="text" type="java.lang.String" value="Name:"/>
185+
</Properties>
186+
</Component>
187+
<Component class="javax.swing.JButton" name="jButtonClear">
188+
<Properties>
189+
<Property name="text" type="java.lang.String" value="Clear"/>
190+
</Properties>
191+
<Events>
192+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButtonClearActionPerformed"/>
193+
</Events>
194+
</Component>
195+
<Component class="javax.swing.JButton" name="jButtonUpdateName">
196+
<Properties>
197+
<Property name="text" type="java.lang.String" value="Update Name"/>
198+
<Property name="enabled" type="boolean" value="false"/>
199+
</Properties>
200+
<Events>
201+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButtonUpdateNameActionPerformed"/>
202+
</Events>
203+
</Component>
204+
</SubComponents>
205+
</Form>

bin/javachat/ui/Plugin.class

233 Bytes
Binary file not shown.

bin/plugins/ClearChat.class

832 Bytes
Binary file not shown.

lib/cling-core-1.0.5.jar

539 KB
Binary file not shown.

lib/cling-support-1.0.5.jar

351 KB
Binary file not shown.

lib/teleal-common-1.0.13.jar

226 KB
Binary file not shown.

src/javachat/JavaChat.java

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package javachat;
2+
3+
import java.net.ConnectException;
4+
import javachat.network.Client;
5+
import javachat.network.Server;
6+
import javachat.ui.ChatWindow;
7+
import plugins.ClearChat;
8+
9+
/**
10+
* Main class for Java Chat
11+
*
12+
* Unless the -server argument is given on the command line a GUI window is
13+
* opened.
14+
*
15+
* @author DrLabman
16+
*/
17+
public class JavaChat {
18+
19+
/** The singleton instance of the chat window */
20+
public static ChatWindow instance = null;
21+
private static Server server;
22+
private static Client client;
23+
24+
public static void println(String text){
25+
instance.println(text);
26+
}
27+
28+
public static boolean startServer(String port, String clientName){
29+
println("Starting server on port " + port);
30+
try {
31+
int portVal = Integer.parseInt(port);
32+
// Start up the server
33+
server = new Server(portVal);
34+
// Make sure the server is up
35+
while (server.isConnected() != true){
36+
try {
37+
Thread.sleep(10);
38+
} catch (InterruptedException ex) {}
39+
}
40+
// Set up a client connecting to our own server for us to send and receive on
41+
client = Client.createClient("localhost", portVal, clientName);
42+
} catch (ConnectException ex) {
43+
return false;
44+
} catch (NumberFormatException e){
45+
println("Port is not a number.");
46+
return false;
47+
}
48+
return true;
49+
}
50+
51+
public static boolean startClient(String hostname, String port, String clientName){
52+
println("Connecting to server " + hostname + ":" + port);
53+
try {
54+
int portVal = Integer.parseInt(port);
55+
client = Client.createClient("localhost", portVal, clientName);
56+
} catch (ConnectException ex) {
57+
return false;
58+
} catch (NumberFormatException e){
59+
println("Port is not a number.");
60+
return false;
61+
}
62+
return true;
63+
}
64+
65+
/**
66+
* Close the server if it is open as well as closing all connected clients
67+
* and/or close the client.
68+
*/
69+
public static void disconnect(){
70+
boolean disconnected = false;
71+
72+
if (server != null && server.isConnected()){
73+
server.disconnect();
74+
disconnected = true;
75+
}
76+
77+
if (client != null && client.isConnected()){
78+
client.disconnect();
79+
disconnected = true;
80+
}
81+
82+
// Error if we weren't able to disconnect
83+
if (!disconnected){
84+
println("Not connected: Unable to disconnect.");
85+
}
86+
}
87+
88+
/**
89+
* Called by the client when a disconnect happens so that the GUI doesn't
90+
* end up marked as connected when we are no longer connected.
91+
*/
92+
public static void disconnected(){
93+
instance.disconnected();
94+
println("Disconnected from server.");
95+
}
96+
97+
/**
98+
* Allow the GUI to get the client so that it can send messages over the
99+
* network.
100+
*
101+
* @return The client object
102+
*/
103+
public static Client getClient(){
104+
return client;
105+
}
106+
107+
/**
108+
* @param args the command line arguments
109+
*/
110+
public static void main(String args[]) {
111+
112+
/*
113+
* Set the Nimbus look and feel
114+
*/
115+
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
116+
/*
117+
* If Nimbus (introduced in Java SE 6) is not available, stay with the
118+
* default look and feel. For details see
119+
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
120+
*/
121+
try {
122+
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
123+
if ("Nimbus".equals(info.getName())) {
124+
javax.swing.UIManager.setLookAndFeel(info.getClassName());
125+
break;
126+
}
127+
}
128+
} catch (ClassNotFoundException ex) {
129+
java.util.logging.Logger.getLogger(ChatWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
130+
} catch (InstantiationException ex) {
131+
java.util.logging.Logger.getLogger(ChatWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
132+
} catch (IllegalAccessException ex) {
133+
java.util.logging.Logger.getLogger(ChatWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
134+
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
135+
java.util.logging.Logger.getLogger(ChatWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
136+
}
137+
//</editor-fold>
138+
139+
/**
140+
* Disconnect from server/clients when shutting down. Needed by the
141+
* server to remove UPnP mapping.
142+
*/
143+
Runtime.getRuntime().addShutdownHook(new Thread() {
144+
@Override
145+
public void run() {
146+
if (instance != null){
147+
if (server != null && server.isConnected()){
148+
server.disconnect();
149+
}
150+
if (client != null && client.isConnected()){
151+
client.disconnect();
152+
}
153+
}
154+
}
155+
});
156+
157+
/*
158+
* Create and display the form
159+
*/
160+
java.awt.EventQueue.invokeLater(new Runnable() {
161+
@Override
162+
163+
164+
165+
public void run() {
166+
instance = new ChatWindow(new ClearChat());
167+
instance.setVisible(true);
168+
}
169+
});
170+
}
171+
}

0 commit comments

Comments
 (0)