public class ClientGUI extends JFrame { private JPanel contentPane; private JTextField txtsend; private static JTextField txtreceive; private static JTextField txtip; private static JTextField txtport; private JTextField txthost; /** * 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. * @throws UnknownHostException * @throws IOException */ public ClientGUI() throws IOException { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 500, 350); contentPane = new JPanel(); contentPane.setBorder(null); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); InetAddress thisIp = InetAddress.getLocalHost(); String ownIP = thisIp.getHostAddress().toString(); JPanel panel = new JPanel(); contentPane.add(panel, BorderLayout.CENTER); panel.setLayout(null); JPanel panel_1 = new JPanel(); panel_1.setBounds(18, 185, 448, 118); panel.add(panel_1); panel_1.setLayout(null); panel_1.setBorder(BorderFactory.createLineBorder(Color.black, 2)); txtreceive = new JTextField(); txtreceive.setToolTipText("Gauta \u017Einut\u0117"); txtreceive.setFont(new Font("Tahoma", Font.BOLD, 15)); txtreceive.setEnabled(false); txtreceive.setBounds(70, 35, 165, 45); panel_1.add(txtreceive); txtreceive.setColumns(10); !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! JButton btnGauti = new JButton("Gauti"); btnGauti.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String serverAddress = txtip.getText(); int port = Integer.parseInt(txtport.getText()); Socket s = new Socket(serverAddress, port); try{ BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream())); String answer = input.readLine(); txtreceive.setText(answer); System.exit(0); s.close(); s.shutdownInput();} catch(IOException e1){} }}); !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! btnGauti.setBounds(300, 46, 89, 23); panel_1.add(btnGauti); JPanel panel_2 = new JPanel(); panel_2.setBounds(18, 85, 448, 91); panel.add(panel_2); panel_2.setLayout(null); panel_2.setBorder(BorderFactory.createLineBorder(Color.black, 2)); txtsend = new JTextField(); txtsend.setFont(new Font("Tahoma", Font.BOLD, 15)); txtsend.setToolTipText("J\u016Bs\u0173 \u017Einut\u0117"); txtsend.setBounds(70, 20, 165, 45); panel_2.add(txtsend); txtsend.setColumns(10); !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! JButton btnNewButton = new JButton("Si\u0173sti"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String message = txtsend.getText(); int port = Integer.parseInt(txtport.getText()); ServerSocket listener = new ServerSocket(port); try{ while (true) { Socket socket = listener.accept(); try { PrintWriter out = new PrintWriter(socket.getOutputStream(), true); out.println(message); txtsend.setText(new String("")); socket.close(); System.exit(0); listener.close();} catch(IOException e1){} }} catch(IOException e1){} finally {} }}); !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! btnNewButton.setBounds(300, 33, 89, 23); panel_2.add(btnNewButton); JPanel panel_3 = new JPanel(); panel_3.setBounds(18, 10, 448, 67); panel.add(panel_3); panel_3.setLayout(null); panel_3.setBorder(new LineBorder(new Color(0, 0, 0), 2)); Label label = new Label("TCP/IP komunikacija"); label.setBounds(5, 20, 171, 28); panel_3.add(label); label.setFont(new Font("Dialog", Font.BOLD, 16)); label.setAlignment(Label.CENTER); txtip = new JTextField(); txtip.setToolTipText("Gav\u0117jo IP Adresas"); txtip.setBounds(241, 11, 121, 20); panel_3.add(txtip); txtip.setColumns(10); txtport = new JTextField(); txtport.setToolTipText("Portas"); txtport.setBounds(384, 22, 54, 20); panel_3.add(txtport); txtport.setColumns(10); txthost = new JTextField(); txthost.setToolTipText("J\u016Bs\u0173 IP adresas"); txthost.setHorizontalAlignment(SwingConstants.CENTER); txthost.setText(ownIP); txthost.setEditable(false); txthost.setBounds(241, 36, 121, 20); panel_3.add(txthost); txthost.setColumns(10); } }