From 6971caf83187ad58eaab160a9c6d2436095b4f3c Mon Sep 17 00:00:00 2001 From: "M.Scholz" Date: Mon, 5 Nov 2012 10:30:50 +0100 Subject: [PATCH] updated some gui stuff --- .../P2P/uebungen/2/p2p_ex2/src/ClientGUI.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ws2012/P2P/uebungen/2/p2p_ex2/src/ClientGUI.java b/ws2012/P2P/uebungen/2/p2p_ex2/src/ClientGUI.java index d18d9a98..acb206b9 100644 --- a/ws2012/P2P/uebungen/2/p2p_ex2/src/ClientGUI.java +++ b/ws2012/P2P/uebungen/2/p2p_ex2/src/ClientGUI.java @@ -14,6 +14,8 @@ import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; public class ClientGUI extends JFrame { @@ -83,8 +85,11 @@ public class ClientGUI extends JFrame { btnPop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); + String received = client.pop(); - textPane.setText(textPane.getText() + received); + String time = sdf.format(new Date()) + ": "; + textPane.setText(textPane.getText() + time + received + "\n"); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); @@ -114,11 +119,11 @@ public class ClientGUI extends JFrame { contentPane.add(lblPort); final JLabel serverInformation = new JLabel(""); - serverInformation.setBounds(300, 20, 130, 28); + serverInformation.setBounds(260, 20, 184, 28); contentPane.add(serverInformation); - JButton btnConnectToServer = new JButton("Connect to Server"); - btnConnectToServer.addActionListener(new ActionListener() { + JButton listenToPort = new JButton("Listen to port"); + listenToPort.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { port = -1; boolean portOkay = false; @@ -139,8 +144,8 @@ public class ClientGUI extends JFrame { if (portOkay) { try { client = new NetworkClient("localhost", port); - serverInformation.setForeground(Color.GREEN); - serverInformation.setText("connected!"); + serverInformation.setForeground(Color.BLUE); + serverInformation.setText("listening to port " + port +"!"); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); @@ -149,8 +154,8 @@ public class ClientGUI extends JFrame { } }); - btnConnectToServer.setBounds(127, 19, 165, 29); - contentPane.add(btnConnectToServer); + listenToPort.setBounds(114, 21, 146, 29); + contentPane.add(listenToPort); } }