diff --git a/ws2012/P2P/uebungen/2/p2p_ex2/src/ClientGUI.java b/ws2012/P2P/uebungen/2/p2p_ex2/src/ClientGUI.java new file mode 100644 index 00000000..9a5fee76 --- /dev/null +++ b/ws2012/P2P/uebungen/2/p2p_ex2/src/ClientGUI.java @@ -0,0 +1,146 @@ +package u1; + + +import java.awt.BorderLayout; +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import javax.swing.JTextField; +import javax.swing.JTextPane; +import javax.swing.JTextArea; +import java.awt.Color; +import javax.swing.JLabel; +import javax.swing.JButton; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.io.IOException; + +public class ClientGUI extends JFrame { + + private JPanel contentPane; + private JTextField userinput; + private JTextField portnumber; + + //private Client client = new Client(); + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + ClientGUI frame = new ClientGUI(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the frame. + */ + public ClientGUI() { + setTitle("Client v0.1"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 450, 369); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + contentPane.setLayout(null); + + userinput = new JTextField(); + userinput.setBounds(18, 88, 413, 28); + contentPane.add(userinput); + userinput.setColumns(10); + + JLabel lblMessage = new JLabel("Message:"); + lblMessage.setBounds(18, 60, 123, 16); + contentPane.add(lblMessage); + + JButton btnPush = new JButton("Push"); + btnPush.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + //TODO + String text = "0" + userinput.getText(); + //client.send(text); + + } + }); + btnPush.setBounds(18, 128, 56, 44); + contentPane.add(btnPush); + + JButton btnPop = new JButton("Pop"); + btnPop.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + } + }); + btnPop.setBounds(96, 128, 56, 44); + contentPane.add(btnPop); + + JTextPane textPane = new JTextPane(); + textPane.setBounds(18, 228, 413, 113); + contentPane.add(textPane); + + JLabel lblServerResponse = new JLabel("Server response:"); + lblServerResponse.setBounds(18, 200, 123, 16); + contentPane.add(lblServerResponse); + + portnumber = new JTextField(); + portnumber.setBounds(54, 20, 61, 28); + portnumber.setText("9999"); + contentPane.add(portnumber); + portnumber.setColumns(10); + + JLabel lblPort = new JLabel("Port:"); + lblPort.setBounds(18, 26, 61, 16); + contentPane.add(lblPort); + + final JLabel serverInformation = new JLabel(""); + serverInformation.setBounds(283, 20, 111, 28); + contentPane.add(serverInformation); + + + JButton btnConnectToServer = new JButton("Connect to Server"); + btnConnectToServer.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int port = -1; + boolean portOkay = false; + try{ + port = Integer.parseInt(portnumber.getText()); + if(1 > port || port > 65535 || portnumber.getText().isEmpty()){ + throw new Exception(); + + } + serverInformation.setText(""); + portOkay = true; + } + catch(Exception ex){ + serverInformation.setForeground(Color.RED); + serverInformation.setText("invalid port!"); + } + + if(portOkay){ + + + //TODO: connect to server..... + + + serverInformation.setForeground(Color.BLUE); + serverInformation.setText("connected"); + } + + + } + }); + btnConnectToServer.setBounds(127, 19, 144, 29); + contentPane.add(btnConnectToServer); + + + } +}