aboutsummaryrefslogtreecommitdiff
path: root/CS2452/GUI_network/Gui.java
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-02-18 08:10:10 -0500
committerTucker Evans <tuckerevans24@gmail.com>2019-02-18 08:10:10 -0500
commitb4dbd2cfa724476162fa6d35941a5d7cdc9c9524 (patch)
tree431af0b75efa29dfa3bab2868a78ab0eb29173c7 /CS2452/GUI_network/Gui.java
parente8b1808eaf87a49e4c34ebbfb66854baa627418c (diff)
Adds all assignments not previously in a git repo
Diffstat (limited to 'CS2452/GUI_network/Gui.java')
-rw-r--r--CS2452/GUI_network/Gui.java108
1 files changed, 108 insertions, 0 deletions
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