From 1a7c5e0fd19cc4c464bd20184fc76ab3e6d97829 Mon Sep 17 00:00:00 2001 From: Hsuan-Hao Date: Thu, 29 Jun 2017 00:02:12 +0200 Subject: [PATCH] modify GUI code --- finalproject_Hao/ColorBlackWhiteConversionGUI.java | 290 +++++++++++++++++++++ 1 file changed, 290 insertions(+) create mode 100644 finalproject_Hao/ColorBlackWhiteConversionGUI.java diff --git a/finalproject_Hao/ColorBlackWhiteConversionGUI.java b/finalproject_Hao/ColorBlackWhiteConversionGUI.java new file mode 100644 index 0000000..109c87c --- /dev/null +++ b/finalproject_Hao/ColorBlackWhiteConversionGUI.java @@ -0,0 +1,290 @@ +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.awt.image.BufferedImage; +import java.util.*; + +public class ColorBlackWhiteConversionGUI +{ + private BufferedImage input_image; + private BufferedImage output_image; + + //for GUI + private JFrame frame; + private JPanel Input; + private JPanel Output; + private String[] name; + private int att[][]; + private ArrayList GUIComponent; + private String userinput = ""; + + boolean occupied = false; + boolean saved = false; + + ColorBlackWhiteConversionGUI() + { + int fill[] = { GridBagConstraints.BOTH, + GridBagConstraints.VERTICAL, + GridBagConstraints.HORIZONTAL, + GridBagConstraints.NONE}; + + int anchor[] = {GridBagConstraints.CENTER, + GridBagConstraints.EAST, + GridBagConstraints.SOUTHEAST, + GridBagConstraints.SOUTH, + GridBagConstraints.SOUTHWEST, + GridBagConstraints.WEST, + GridBagConstraints.NORTHWEST, + GridBagConstraints.NORTH, + GridBagConstraints.NORTHEAST}; + + String n[] = { "Input:", + "Output:", + "hint...", + "Load", + "BW", + "Gray", + "Save", + "Quit"}; + + name = n; + + //x, y, width, height, weight-x, weight-y, GridBagConstraints.fill, GridBagConstraints.anchor + int a[][] = {{0, 0, 1, 1, 0, 0, fill[3], anchor[5]}, //input (word) + {9, 0, 1, 1, 0, 0, fill[3], anchor[5]}, //output (word) + {0, 11, 7, 1, 0, 0, fill[3], anchor[5]}, //hint... (word) + + //Image field + {0, 1, 4, 8, 0, 0, fill[3], anchor[5]}, //input image + {9, 1, 4, 8, 0, 0, fill[3], anchor[1]}, //output image + + //Buttons + {0, 10, 1, 1, 0, 0, fill[3], anchor[0]}, //Load file button + {6, 6, 1, 1, 0, 0, fill[3], anchor[0]}, //Black and White button + {6, 7, 1, 1, 0, 0, fill[3], anchor[0]}, //Gray Scale button + {9, 10, 1, 1, 0, 0, fill[3], anchor[0]}, //Save file button + {9, 11, 1, 1, 0, 0, fill[2], anchor[0]}, //Quit button + + //Text field + {1, 10, 3, 1, 0, 0, fill[2], anchor[0]}, //Load file text + {10, 10, 3, 1, 0, 0, fill[2], anchor[0]} //Save file text + }; + + att = a; + + frame = new JFrame(); + frame.setTitle("Color Black White Conversion"); + frame.setSize(1200, 500); + frame.setLayout(new GridBagLayout()); + frame.setLocationRelativeTo(null); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + Output = new JPanel(); + Input = new JPanel(); + Input.setBackground(Color.RED); + Output.setBackground(Color.WHITE); + + GUIComponent = new ArrayList(15); + } + + public void run() + { + for (int i=0; i<3; i++) + { + JLabel nLabel = new JLabel(name[i]); + GUIComponent.add(nLabel); + } + + LoadFile file = new LoadFile(); + input_image = file.Load_File("test.jpg"); + output_image = file.Load_File("Blank.jpg"); + + JScrollPane scrollPane = new JScrollPane(new JLabel(new ImageIcon(input_image))); // put input_Image into label + Input.add(scrollPane); + GUIComponent.add(Input); + + JScrollPane scrollPane2 = new JScrollPane(new JLabel(new ImageIcon(output_image)));//put output_Image into label + Output.add(scrollPane2); + GUIComponent.add(Output); + + //add Buttons + for (int k=3; k