From: Hsuan-Hao Date: Wed, 28 Jun 2017 22:02:51 +0000 (+0200) Subject: modify GUI code X-Git-Url: http://git.risc.jku.at/gitweb/?a=commitdiff_plain;h=02124f84519a1d797e9588edc179b6b813c41562;p=ipau%2FColorBlackWhiteConversion.git modify GUI code --- diff --git a/finalproject_Hao/BlackandWhite.java b/finalproject_Hao/BlackandWhite.java index 299225c..38f6808 100644 --- a/finalproject_Hao/BlackandWhite.java +++ b/finalproject_Hao/BlackandWhite.java @@ -3,10 +3,17 @@ import java.awt.image.BufferedImage; public class BlackandWhite { - BufferedImage image; + BufferedImage image; int width; int height; + public BlackandWhite() + { + image = null; + width = 0; + height = 0; + } + public BufferedImage Black_and_White(BufferedImage image) { try { diff --git a/finalproject_Hao/ColorBlackWhiteConversion.java b/finalproject_Hao/ColorBlackWhiteConversion.java deleted file mode 100644 index 6cc3dfd..0000000 --- a/finalproject_Hao/ColorBlackWhiteConversion.java +++ /dev/null @@ -1,212 +0,0 @@ -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.*; -import java.io.*; -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.util.*; - -public class ColorBlackWhiteConversion -{ - String Filename; - static BufferedImage input_image; - static BufferedImage output_image; - - //for GUI - private JPanel Output; - private JPanel Input; - private JFrame frame; - private String[] name; - private int att[][]; - private ArrayList 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