Advertisement
Guest User

Untitled

a guest
May 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. package php;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6.  
  7. class MyFrame extends JFrame {
  8.  
  9. private JButton btnSprawdz = new JButton("Sprawdź");
  10. private JButton btnExit = new JButton("Zamknij");
  11.  
  12. private JTextArea txtA = new JTextArea();
  13.  
  14. private JLabel lblA = new JLabel("Wpisz tekst:");
  15. private int wyjscie;
  16.  
  17. public static void main(String[] args) {
  18. MyFrame f = new MyFrame();
  19. f.setVisible(true);
  20. }
  21.  
  22. public MyFrame() {
  23. setTitle("Checkinator");
  24. setSize(400, 200);
  25. setLocation(new Point(300, 200));
  26. setLayout(null);
  27. setResizable(false);
  28.  
  29. initComponent();
  30. initEvent();
  31. }
  32.  
  33. private void initComponent() {
  34.  
  35. btnSprawdz.setBounds(140, 130, 100, 25);
  36. btnExit.setBounds(260, 130, 100, 25);
  37.  
  38. txtA.setBounds(100, 10, 260, 100);
  39.  
  40. lblA.setBounds(20, 10, 100, 20);
  41.  
  42. add(btnSprawdz);
  43. add(btnExit);
  44.  
  45. add(lblA);
  46.  
  47. add(txtA);
  48. txtA.setLineWrap(true);
  49. txtA.setWrapStyleWord(true);
  50. }
  51.  
  52. private void initEvent() {
  53.  
  54. this.addWindowListener(new WindowAdapter() {
  55. public void windowClosing(WindowEvent e) {
  56. System.exit(1);
  57. }
  58. });
  59.  
  60. btnExit.addActionListener(new ActionListener() {
  61. public void actionPerformed(ActionEvent e) {
  62. btnExit(e);
  63. }
  64. });
  65.  
  66. btnSprawdz.addActionListener(new ActionListener() {
  67. public void actionPerformed(ActionEvent e) {
  68. btnTutupClick(e);
  69. }
  70. });
  71.  
  72. }
  73.  
  74. private void btnTutupClick(ActionEvent evt) {
  75.  
  76. try {
  77. String lancuch = txtA.getText().toLowerCase();
  78. String slowo[] = lancuch.split("[\\p{Punct}\\s+]");
  79.  
  80. for (int i = 0; i < slowo.length; i++) {
  81. int licznik = 0;
  82. wyjscie = 0;
  83. for (int j = 0; j < slowo.length; j++) {
  84.  
  85. if (slowo[i].equals(slowo[j])) {
  86. if (j < i) {
  87. break;
  88. }
  89.  
  90. licznik++;
  91. }
  92. }
  93.  
  94. if (licznik > 1) {
  95. JOptionPane.showMessageDialog(null, "True");
  96. wyjscie = licznik;
  97. break;
  98. }
  99.  
  100. }
  101. if (wyjscie <= 1 && wyjscie == 0){
  102. JOptionPane.showMessageDialog(null, "False");
  103. return;
  104. }
  105.  
  106.  
  107. } catch (Exception e) {
  108. System.out.println(e);
  109. JOptionPane.showMessageDialog(null, e.toString(), "Błąd", JOptionPane.ERROR_MESSAGE);
  110. }
  111. }
  112.  
  113. private void btnExit(ActionEvent evt) {
  114. System.exit(0);
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement