From f7435e6b81dacf595c8392a129a7ea24a7a0767a Mon Sep 17 00:00:00 2001 From: Yash Ugrankar Date: Sun, 30 Oct 2016 20:56:23 +0530 Subject: [PATCH] Add file chooser to GUI Issue #17: A button has been added to the GUI, which when clicked creates a JFileChooser object that allows the user to select a text file from which text is fetched. This fetched text is then used to replace the contents of the input text area. --- .gitignore | 1 + build/built-jar.properties | 4 ++ .../classes/random/text/generator/Gui$1.class | Bin 515 -> 2602 bytes .../classes/random/text/generator/Gui$2.class | Bin 0 -> 515 bytes build/classes/random/text/generator/Gui.class | Bin 2266 -> 3482 bytes src/random/text/generator/Gui.java | 50 ++++++++++++++++-- 6 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100644 build/built-jar.properties create mode 100644 build/classes/random/text/generator/Gui$2.class diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..838458f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/dist/ \ No newline at end of file diff --git a/build/built-jar.properties b/build/built-jar.properties new file mode 100644 index 0000000..ebd1c18 --- /dev/null +++ b/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 30 Oct 2016 13:30:07 +0530 + + +D\:\\OSS\\Hacktoberfest\\Random-Text-Generator= diff --git a/build/classes/random/text/generator/Gui$1.class b/build/classes/random/text/generator/Gui$1.class index 86169fc06065535740d254704d3cef08e8a6c9e4..e0d4e22026b0ff9adcf8faea425879119b7f1ff3 100644 GIT binary patch literal 2602 zcmb7GTT>iG6#kmM%w`w_mavgrgcyv=Ca_7=#Do|nNCLPE$P!}WExof1OfoyOndt@M z{eG$PC2#r%^ua2ttdb2eRhEyIKf?dvi+XwnHY~S_TRW$_PoH!8T)sXtfBy69ZvdXf z*L&~;Mim)TWL%L~6v^r6MqbARCN)gycoow+5-21vqsA*5W_7gSs*X!|O~W-EZEA5H zuPe?QI^M)vO6zS6H*}n@su`Gu?!M8}SZ;*6SNxN0qARe45 zmW5fBmg~$|Ws&1WVKeM)JT>5wk+@v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an$tNdOl)L6|&As06i?$y!%miVx=5L=$62(e>O~Go0KD^rMNbpi&?7 zcIlhhG`6E|qmNT)F2Rx9$l;+iBabQ~h0HXUkhg8x=bha?cCbes{1lJ{Mq|PLUw4OY rX}9+d=WYpgyK_i?3!Jg^{GW^W>!NVLtb;=oNlkTxJe5y7O#-nJG| diff --git a/build/classes/random/text/generator/Gui$2.class b/build/classes/random/text/generator/Gui$2.class new file mode 100644 index 0000000000000000000000000000000000000000..70fefa5c51987eaf96d95becaf2b1b7924d1bf5b GIT binary patch literal 515 zcmZ`$!A`lCn*mxO5CPnU+4$!hZHG$QNY6<*D~|xK{FZ3n8CSLO6X3=<5-Y;;AyV<(b!GITjCA` zaXg8%dzH$1t4%NIR594yDAj?ul$m;gxT6t&<@EH03c@IsYH%ZxVbpg}#l8az1%~QU zVTRgLuHIrOW#Vqg)xf>;MH?FwbO3)a14|7NL!<& z8g!^D@`_}+gp4qMI01W~(l*^I)8GqM$#!N5gzMzdq<_VyB$gEyKVdvgkb7JRWd8+l eO7;JV6z3v2l!!I3i87%{))v;tvPsS)1PZ^&>$9XAYYLqRr0 z11>ySl|+h@FVY}7ui%rg3Lt&yJ5$%B=d3{D>7GgJZm5+20w@o$?7>7 zsFTEpWq3Z0kI4K{9UqJ1;|2yKyaAEuk=R}^a0s6e$|og=Ps#9U89t-qvj&gJ!+j2) z*YO1%U({eux~?jZ73@kyRWx)gC~j@vD{Dwim2Efg6*InC_A~2@%ydAVCGk{4ctk_& znBzMBaSiSL0~a(z#=N}Juw%+`)!AxsPL*fvxdJJPDKBRiF4$#9_H|;!zvj^UeRuG9 zs_M`~L>y>{&X?^X4c#+!-CnepGnFOBUC5lC5GtjjCEHbnP3-eRCA;&Qvh%7uWzTIP z6i_LYSU>EHDyW=4>Md*NZS^Ay=A@4(s$QUh;8RzutJkPL^L zgCXUqy9M+1JQy=xwVYEEj-WVBNFEaWnHa{1iDP)u#2B7rkv5}}6%7xVlqx6JZ;hzk zH1Q>Td81l@R;o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F*d|o z9!_=!pNih k3>{q17AI2MmKp~)pUcF#VuBATfAI^5UX#fBK diff --git a/src/random/text/generator/Gui.java b/src/random/text/generator/Gui.java index 772015c..f9e5a08 100644 --- a/src/random/text/generator/Gui.java +++ b/src/random/text/generator/Gui.java @@ -2,10 +2,13 @@ import java.awt.Component; import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; +import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; @@ -13,6 +16,9 @@ public class Gui { + private RandomTextGenerator generator; + //private static final int DEFAULT_WORD_AMOUNT; + public Gui() { init(); } @@ -28,23 +34,57 @@ public void init() { panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); frame.add(panel); - JLabel label = new JLabel("Click the button on the bottom!"); - label.setAlignmentX(Component.CENTER_ALIGNMENT); - panel.add(label); - + JLabel headerLabel = new JLabel("Click the button on the bottom!"); + headerLabel.setAlignmentX(Component.CENTER_ALIGNMENT); + panel.add(headerLabel); + + JComboBox generatorSelectBox = new JComboBox<>(); + generatorSelectBox.addItem("SpaceEfficientGenerator"); + generatorSelectBox.addItem("SpeedEfficientGenerator"); + generatorSelectBox.setAlignmentX(Component.RIGHT_ALIGNMENT); + panel.add(generatorSelectBox); + JTextArea inputTextArea = new JTextArea(5, 5); inputTextArea.setText(RandomTextGenerator.getDefaultText()); inputTextArea.setAlignmentX(Component.CENTER_ALIGNMENT); + inputTextArea.setLineWrap(true); + inputTextArea.setWrapStyleWord(true); panel.add(inputTextArea); JTextArea outputTextArea = new JTextArea(5, 5); - outputTextArea.setText("Not randomly generated text."); + outputTextArea.setText("Result"); + outputTextArea.setEditable(false); outputTextArea.setAlignmentX(Component.CENTER_ALIGNMENT); + outputTextArea.setLineWrap(true); + outputTextArea.setWrapStyleWord(true); panel.add(outputTextArea); JButton generateTextButton = new JButton("Generate text"); generateTextButton.setAlignmentX(Component.CENTER_ALIGNMENT); panel.add(generateTextButton); + + JLabel executionTimeLabel = new JLabel(); + panel.add(executionTimeLabel); + + generateTextButton.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e) { + String generatorType = (String)generatorSelectBox.getSelectedItem(); + String inputText = inputTextArea.getText(); + switch(generatorType){ + case "SpeedEfficientGenerator": + generator = new SpeedEfficientGenerator(inputText); + break; + default: + generator = new SpaceEfficientGenerator(inputText); + } + long startTime = System.currentTimeMillis(); + outputTextArea.setText(generator.generateText(200)); + long stopTime = System.currentTimeMillis(); + long elapsedTime = stopTime - startTime; + executionTimeLabel.setText("Time taken: " + elapsedTime + "ms"); + } + }); frame.pack(); frame.setLocationRelativeTo(null);