From: Hsuan-Hao Date: Wed, 28 Jun 2017 20:11:28 +0000 (+0200) Subject: add GUI version X-Git-Url: http://git.risc.jku.at/gitweb/?a=commitdiff_plain;h=b9ff24e98da1257a1978edb49788e91c531c7c51;p=ipau%2FColorBlackWhiteConversion.git add GUI version --- diff --git a/finalproject_Hao/BlackandWhite.java b/finalproject_Hao/BlackandWhite.java new file mode 100644 index 0000000..299225c --- /dev/null +++ b/finalproject_Hao/BlackandWhite.java @@ -0,0 +1,42 @@ +import java.awt.*; +import java.awt.image.BufferedImage; + +public class BlackandWhite { + + BufferedImage image; + int width; + int height; + + public BufferedImage Black_and_White(BufferedImage image) { + + try { + this.image = image; + width = image.getWidth(); + height = image.getHeight(); + + for(int i=0; i GUIComponent; + private String userinput = ""; + //private String result = ""; + + ColorBlackWhiteConversion() + { + 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:", + "Load", + "BW", + "Gray", + "Save",}; + + 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) + + //Text 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 + {6, 6, 1, 1, 0, 0, fill[3], anchor[0]}, //Black and White + {6, 7, 1, 1, 0, 0, fill[3], anchor[0]}, //Gray Scale + {9, 10, 1, 1, 0, 0, fill[3], anchor[0]}, //Save file + {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(10); + } + + public void run() + { + for (int i=0; i<2; i++) + { + JLabel nLabel = new JLabel(name[i]); + GUIComponent.add(nLabel); + } + + + JScrollPane scrollPane = new JScrollPane(new JLabel(new ImageIcon(input_image)));//把Image放進label裡 + Input.add(scrollPane); + GUIComponent.add(Input); + + JScrollPane scrollPane2 = new JScrollPane(new JLabel(new ImageIcon(output_image)));//把Image放進label裡 + Output.add(scrollPane2); + GUIComponent.add(Output); + + //add Buttons + for (int k=2; k<6; k++) + { + JButton nButton = new JButton(name[k]); + GUIComponent.add(nButton); + } + + JTextField Load_text = new JTextField(""); + GUIComponent.add(Load_text); + + JTextField Save_text = new JTextField(""); + GUIComponent.add(Save_text); + + for (int l=0; l