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/Gui.java | 108 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 CS2452/GUI_network/Gui.java (limited to 'CS2452/GUI_network/Gui.java') diff --git a/CS2452/GUI_network/Gui.java b/CS2452/GUI_network/Gui.java new file mode 100644 index 0000000..2187030 --- /dev/null +++ b/CS2452/GUI_network/Gui.java @@ -0,0 +1,108 @@ +package assign6; + +import java.awt.*; +import java.awt.event.*; +import java.awt.image.*; +import java.io.*; +import java.util.concurrent.Semaphore; + +import javax.imageio.ImageIO; +import javax.swing.*; + +public class Gui extends JFrame implements ActionListener, MouseListener +{ + JPanel panel; + JLabel label; + BufferedImage image; + Color color; + Semaphore write; + boolean sc; + + + public Gui(String filename, Color color, Semaphore write, boolean sc) + { + this.color = color; + this.sc = sc; + + panel = new JPanel(new GridLayout(1,1)); + panel.setBackground(color); + try + { + image = ImageIO.read(new File(filename)); + } catch (IOException e) + { + e.printStackTrace(); + } + label = new JLabel(new ImageIcon(new ImageIcon(image).getImage().getScaledInstance(500, 500, Image.SCALE_DEFAULT))); + + panel.add(label); + panel.addMouseListener(this); + this.add(panel); + + this.write = write; + + } + + public void actionPerformed(ActionEvent e) + { + + } + + public void mouseClicked(MouseEvent e) + { + write.release(); + changeImage(); + } + + + public void mouseEntered(MouseEvent e) + { + + } + + public void mouseExited(MouseEvent e) + { + + } + + public void mousePressed(MouseEvent e) + { + + } + + public void mouseReleased(MouseEvent e) + { + + } + + public void changeImage() + { + + String filename; + Color color; + if(sc) + { + filename = "img2.jpg"; + color = Color.GREEN; + } + else + { + filename = "img1.jpg"; + color = Color.BLUE; + } + + try + { + image = ImageIO.read(new File(filename)); + } catch (IOException e) + { + e.printStackTrace(); + } + label.setIcon(new ImageIcon(new ImageIcon(image).getImage().getScaledInstance(500, 500, Image.SCALE_DEFAULT))); + + panel.setBackground(color); + panel.repaint(); + + sc = !sc; + } +} \ No newline at end of file -- cgit v1.1