Marauroa Chat Tutorial/Swing Client: Difference between revisions
Content deleted Content added
imported>Hendrik Brummermann No edit summary |
imported>Fjacob m →Code: Some import cleanup in View.java, some changes to reflect the changes in Client.java |
||
Line 6:
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">
import java.awt.event.*;
import
public class View extends JFrame implements ActionListener {
Line 27 ⟶ 23:
jSayButton.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String message = jInputField.getText();
jInputField.setText("");
client.
}
});
jConnectButton.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Line 56 ⟶ 54:
}
@Override
public void actionPerformed(ActionEvent e) {
if (client != null) {
Line 130 ⟶ 129:
The only thing left for the Swing client now is a main method. Here is the source code
<source lang="java">
public final class Chat {
private Chat() {}
| |||