Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import java.awt.BorderLayout;
- import java.awt.Font;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.net.ServerSocket;
- import java.net.Socket;
- import javax.swing.JTextField;
- import javax.swing.JTextArea;
- import javax.swing.JButton;
- public class Receiver_1 {
- private JFrame frame;
- private JTextField textField;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Receiver_1 window = new Receiver_1();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public Receiver_1() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.setBounds(100, 100, 450, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- JLabel lblNewLabel = new JLabel("String Receive");
- lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 12));
- lblNewLabel.setBounds(37, 62, 107, 13);
- frame.getContentPane().add(lblNewLabel);
- JLabel lblMessage = new JLabel("Message");
- lblMessage.setFont(new Font("Tahoma", Font.BOLD, 12));
- lblMessage.setBounds(37, 93, 107, 13);
- frame.getContentPane().add(lblMessage);
- textField = new JTextField();
- textField.setFont(new Font("Tahoma", Font.BOLD, 12));
- textField.setBounds(156, 60, 96, 19);
- frame.getContentPane().add(textField);
- textField.setColumns(10);
- try {
- ServerSocket ss = new ServerSocket(8081);
- while (true) {
- Socket s = ss.accept();
- DataInputStream in = new DataInputStream(s.getInputStream());
- String strSender = in.readUTF();
- textField.setText(strSender);
- String strToSend = "";
- // try {
- // int intCast = Integer.parseInt(strSender.trim());
- //
- // if (intCast % 2 == 0) {
- // strToSend = "You sent even number";
- // } else {
- // strToSend = "You sent odd number";
- // }
- // } catch (NumberFormatException pe) {
- // strToSend = "Please send a number la!";
- // }
- //
- // DataOutputStream out = new DataOutputStream(s.getOutputStream());
- // out.writeUTF(strToSend);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- JTextArea textArea = new JTextArea();
- textArea.setFont(new Font("Monospaced", Font.PLAIN, 13));
- textArea.setBounds(154, 104, 220, 100);
- frame.getContentPane().add(textArea);
- JButton btnNewButton = new JButton("Send to Sender");
- btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 12));
- btnNewButton.setBounds(132, 232, 139, 21);
- frame.getContentPane().add(btnNewButton);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement