Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
- */
- package onlyFrame;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.Map;
- /**
- *
- * @author User
- */
- public class MainForm extends javax.swing.JFrame {
- /**
- * Creates new form MainForm
- */
- public MainForm() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- jScrollPane1 = new javax.swing.JScrollPane();
- txtEntry = new javax.swing.JTextArea();
- jScrollPane2 = new javax.swing.JScrollPane();
- txtResult = new javax.swing.JTextArea();
- btnProses = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- txtEntry.setColumns(20);
- txtEntry.setFont(new java.awt.Font("DialogInput", 0, 18)); // NOI18N
- txtEntry.setLineWrap(true);
- txtEntry.setRows(5);
- jScrollPane1.setViewportView(txtEntry);
- txtResult.setColumns(20);
- txtResult.setFont(new java.awt.Font("DialogInput", 0, 18)); // NOI18N
- txtResult.setLineWrap(true);
- txtResult.setRows(5);
- jScrollPane2.setViewportView(txtResult);
- btnProses.setText("Proses");
- btnProses.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnProsesActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1)
- .addComponent(jScrollPane2)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(233, 233, 233)
- .addComponent(btnProses)
- .addContainerGap(353, Short.MAX_VALUE))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(btnProses)
- .addContainerGap())
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addContainerGap())
- );
- pack();
- setLocationRelativeTo(null);
- }// </editor-fold>
- private void btnProsesActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- Map<String, Integer> duplicatesV3 = countDuplicateCharactersVCP1(txtEntry.getText().replaceAll("\\s", "").toUpperCase());
- // Object[] arrString = duplicatesV3.entrySet().toArray();
- // Arrays.sort(arrString);
- // System.out.println(Arrays.toString(arrString));
- txtResult.setText(Arrays.toString(duplicatesV3.entrySet().toArray()));
- }
- public static Map<String, Integer> countDuplicateCharactersVCP1(String word) {
- if (word == null || word.isEmpty()) {
- // or throw IllegalArgumentException
- return Collections.emptyMap();
- }
- Map<String, Integer> result = new HashMap<>();
- for (int x = 0; x < word.length(); x++) {
- int cp = word.codePointAt(x);
- String ch = String.valueOf(Character.toChars(cp));
- if (Character.charCount(cp) == 2) { // 2 means a surrogate pair
- x++;
- }
- result.compute(ch, (k, v) -> (v == null) ? 1 : ++v);
- }
- return result;
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new MainForm().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btnProses;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JScrollPane jScrollPane2;
- private javax.swing.JTextArea txtEntry;
- private javax.swing.JTextArea txtResult;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment