From b4dbd2cfa724476162fa6d35941a5d7cdc9c9524 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Mon, 18 Feb 2019 08:10:10 -0500 Subject: Adds all assignments not previously in a git repo --- CS2452/GUI_network/MGui.java | 92 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 CS2452/GUI_network/MGui.java (limited to 'CS2452/GUI_network/MGui.java') diff --git a/CS2452/GUI_network/MGui.java b/CS2452/GUI_network/MGui.java new file mode 100644 index 0000000..a0879c6 --- /dev/null +++ b/CS2452/GUI_network/MGui.java @@ -0,0 +1,92 @@ +package assign6; + +import java.net.*; +import java.util.concurrent.Semaphore; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +import java.io.*; + +public class MGui +{ + + public static void main(String[] args) + { + Gui g = null; + Semaphore write = new Semaphore(1); + try + { + write.acquire(); + } catch (InterruptedException e1) + { + e1.printStackTrace(); + } + ServerSocket ss; + Socket s = null; + + if (args[0].compareTo("server") == 0) + { + try + { + ss = new ServerSocket(Integer.parseInt(args[1])); + s = ss.accept(); + } catch (NumberFormatException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + g = new Gui("img1.jpg",Color.BLUE, write,true); + g.setSize(1000, 1000); + g.setLocation(32, 32); + g.setVisible(true); + g.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + SocketWriter sw = new SocketWriter(s,write); + + + } + else if (args[0].compareTo("client") == 0) + { + + InetAddress address = null; + int port = 0; + + try + { + address = InetAddress.getByName(args[1]); + port = Integer.parseInt(args[2]); + + } catch (UnknownHostException e) + { + e.printStackTrace(); + } + + try + { + s = new Socket(address, port); + } catch (IOException e) + { + e.printStackTrace(); + } + + g = new Gui("img2.jpg",Color.GREEN,write,false); + g.setSize(1000, 1000); + g.setLocation(500, 500); + g.setVisible(true); + g.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + SocketWriter sw = new SocketWriter(s,write); + + } + + SocketReader sr = new SocketReader(s,g); + + } + +} -- cgit v1.1