Marauroa Chat Tutorial/Swing Client: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>Hendrik Brummermann splitted Marauroa Tutorial |
imported>Fjacob m →Code: Some import cleanup in View.java, some changes to reflect the changes in Client.java |
||
| (25 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{{Navigation for Marauroa Top|Using}} |
|||
== Swing client == |
|||
{{Navigation for Marauroa Users}} |
|||
| ⚫ | |||
{{Marauroa Chat Tutorial}} |
|||
| ⚫ | |||
The design of our Client class allows us to easily use it in something more complex then Test class above. Here is the example of a simple Swing application that uses Client as a communication tool |
The design of our Client class allows us to easily use it in something more complex then Test class above. Here is the example of a simple Swing application that uses Client as a communication tool |
||
<source lang="java"> |
<source lang="java"> |
||
import javax.swing.*; |
|||
import java.awt.event.*; |
import java.awt.event.*; |
||
import |
import javax.swing.*; |
||
import java.net.URL; |
|||
import java.util.*; |
|||
import java.awt.*; |
|||
public class View extends JFrame implements ActionListener { |
public class View extends JFrame implements ActionListener { |
||
| Line 24: | Line 23: | ||
jSayButton.addActionListener( |
jSayButton.addActionListener( |
||
new ActionListener() { |
new ActionListener() { |
||
@Override |
|||
public void actionPerformed(ActionEvent e) { |
public void actionPerformed(ActionEvent e) { |
||
String message = jInputField.getText(); |
String message = jInputField.getText(); |
||
jInputField.setText(""); |
jInputField.setText(""); |
||
client. |
client.sendMessage(message); |
||
} |
} |
||
}); |
}); |
||
jConnectButton.addActionListener( |
jConnectButton.addActionListener( |
||
new ActionListener() { |
new ActionListener() { |
||
@Override |
|||
public void actionPerformed(ActionEvent e) { |
public void actionPerformed(ActionEvent e) { |
||
try { |
try { |
||
| Line 53: | Line 54: | ||
} |
} |
||
@Override |
|||
public void actionPerformed(ActionEvent e) { |
public void actionPerformed(ActionEvent e) { |
||
if (client != null) { |
if (client != null) { |
||
| Line 127: | Line 129: | ||
The only thing left for the Swing client now is a main method. Here is the source code |
The only thing left for the Swing client now is a main method. Here is the source code |
||
<source lang="java"> |
<source lang="java"> |
||
final class Chat { |
public final class Chat { |
||
private Chat() {} |
private Chat() {} |
||
| Line 135: | Line 137: | ||
} |
} |
||
</source> |
</source> |
||
== Deployment == |
|||
You still use the same command for compilation |
You still use the same command for compilation |
||
<pre> |
<pre> |
||
| Line 145: | Line 148: | ||
java -cp marauroa.jar;log4j.jar;. Chat |
java -cp marauroa.jar;log4j.jar;. Chat |
||
</pre> |
</pre> |
||
== Next Steps == |
|||
Congratulations, you completed this tutorial. The final sections will list some ideas for [[Marauroa Chat Tutorial/Next Steps|further steps to improve]]. |
|||
[[Category:Marauroa]] |
|||
{{#breadcrumbs: [[Marauroa]] | [[Navigation for Marauroa Users|Using]] | [[Marauroa Chat Tutorial|Tutorial]] | [[Marauroa Chat Tutorial/Swing Client|Swing Client]]}} |
|||