The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
WoorenApplicatie
Posted by: Roy Theunissen | September 4, 2010 @ 4:38am
Java Code
[
Download
]
package gui; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Arrays; // Zelf toegevoegd import java.util.Collection; import java.util.Collections; // Zelf toegevoegd import java.util.Comparator; // Zelf toegevoegd import javax.swing.BorderFactory; import java.util.Iterator; // Zelf toegevoegd import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import java.util.List; // Zelf toegevoegd import javax.swing.WindowConstants; import javax.swing.SwingUtilities; /** * This code was edited or generated using CloudGarden's Jigloo * SWT/Swing GUI Builder, which is free for non-commercial * use. If Jigloo is being used commercially (ie, by a corporation, * company or business for any purpose whatever) then you * should purchase a license for each developer using Jigloo. * Please visit www.cloudgarden.com for details. * Use of Jigloo implies acceptance of these licensing terms. * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE. */ public class WoordenFrame extends javax.swing.JFrame { private static final long serialVersionUID = 1L; private JPanel pnInput; private JPanel pnOutput; private JButton btConcordantie; private JButton btFrequentie; private JButton btSorteer; private JButton btAantal; private JScrollPane spInput; private JTextArea taOutput; private JTextArea taInput; private JScrollPane spOutput; /** * Auto-generated main method to display this JFrame */ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { WoordenFrame inst = new WoordenFrame(); inst.setLocationRelativeTo(null); inst.setVisible(true); } }); } public WoordenFrame() { super(); initGUI(); } private void initGUI() { try { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setTitle("Woorden"); getContentPane().setLayout(null); { pnInput = new JPanel(); getContentPane().add(pnInput); pnInput.setLayout(null); pnInput.setBounds(12, 12, 368, 124); pnInput.setBorder(BorderFactory.createTitledBorder("Input")); pnInput.setLayout(null); { btAantal = new JButton(); pnInput.add(btAantal); btAantal.setText("Aantal"); btAantal.setBounds(243, 20, 114, 21); btAantal.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btAantalActionPerformed(evt); } }); } { btSorteer = new JButton(); pnInput.add(btSorteer); btSorteer.setText("Sorteer"); btSorteer.setBounds(243, 44, 114, 21); btSorteer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btSorteerActionPerformed(evt); } }); } { btFrequentie = new JButton(); pnInput.add(btFrequentie); btFrequentie.setText("Frequentie"); btFrequentie.setBounds(243, 68, 114, 21); btFrequentie.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btFrequentieActionPerformed(evt); } }); } { btConcordantie = new JButton(); pnInput.add(btConcordantie); btConcordantie.setText("Concordantie"); btConcordantie.setBounds(243, 93, 114, 21); btConcordantie.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btConcordantieActionPerformed(evt); } }); } { spInput = new JScrollPane(); pnInput.add(spInput); spInput.setBounds(12, 19, 219, 95); { taInput = new JTextArea(); spInput.setViewportView(taInput); } } } { pnOutput = new JPanel(); getContentPane().add(pnOutput); pnOutput.setBorder(BorderFactory.createTitledBorder("Output")); pnOutput.setBounds(11, 142, 367, 121); pnOutput.setLayout(null); { spOutput = new JScrollPane(); pnOutput.add(spOutput); spOutput.setBounds(12, 19, 344, 89); { taOutput = new JTextArea(); spOutput.setViewportView(taOutput); } } } pack(); setSize(400, 300); //Standaard tekst, effe voor de handigheid. taInput.setText("een, twee, drie, vier,\nhoedje van, hoedje van,\neen, twee, drie, vier,\nhoedje van papier."); } catch (Exception e) { e.printStackTrace(); } } private void btAantalActionPerformed(ActionEvent evt) { //Reset de output even taOutput.setText(""); //Pak de input string en split het op een aantal karakters String delims = "[ .,?!\n]+"; String[] alleWoordenArray = taInput.getText().split(delims); List alleWoorden = Arrays.asList(alleWoordenArray); //Laat zien dat het werkt taOutput.setText(taOutput.getText() + "Totaal aantal woorden: "+Integer.toString(alleWoorden.size()) +"\n"); //Voeg elk woord toe wat nog niet in de unieke woorden array zit List uniekeWoorden = new ArrayList(); Iterator iterator = alleWoorden.iterator(); while (iterator.hasNext()) { String woord = (String) iterator.next(); if (!uniekeWoorden.contains(woord)) { uniekeWoorden.add(woord); //taOutput.setText(taOutput.getText() + woord +"\n"); } } //Laat zien dat dit ook goed gelukt is taOutput.setText(taOutput.getText() + "Aantal verschillende woorden: "+Integer.toString(uniekeWoorden.size()) +"\n"); } private void btSorteerActionPerformed(ActionEvent evt) { //Reset de output even taOutput.setText(""); //Pak de input string en split het op een aantal karakters String delims = "[ .,?!\n]+"; String[] alleWoordenArray = taInput.getText().split(delims); List alleWoorden = Arrays.asList(alleWoordenArray); //Voeg elk woord toe wat nog niet in de unieke woorden array zit List uniekeWoorden = new ArrayList(); Iterator iterator = alleWoorden.iterator(); while (iterator.hasNext()) { String woord = (String) iterator.next(); if (!uniekeWoorden.contains(woord)) { uniekeWoorden.add(woord); } } //Maak een comparator voor analfabetische volgorde class analfabetischComp implements Comparator<String> { // Gebruik de gewone string comparator, maar wissel de argumenten om public int compare(String strA, String strB) { // NOTENOTE: Let op waar strB en strA staat! return strB.compareTo(strA); } } //Sorteer de lijst allfabetisch Collections.sort(uniekeWoorden, new analfabetischComp()); //Laat zien dat dit ook goed gelukt is iterator = uniekeWoorden.iterator(); while (iterator.hasNext()) { String woord = (String) iterator.next(); taOutput.setText(taOutput.getText() + woord +"\n"); } } private void btFrequentieActionPerformed(ActionEvent evt) { // to do } private void btConcordantieActionPerformed(ActionEvent evt) { // to do } }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.67 / 8
57 Votes