Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package php;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- class MyFrame extends JFrame {
- private JButton btnSprawdz = new JButton("Sprawdź");
- private JButton btnExit = new JButton("Zamknij");
- private JTextArea txtA = new JTextArea();
- private JLabel lblA = new JLabel("Wpisz tekst:");
- private int wyjscie;
- public static void main(String[] args) {
- MyFrame f = new MyFrame();
- f.setVisible(true);
- }
- public MyFrame() {
- setTitle("Checkinator");
- setSize(400, 200);
- setLocation(new Point(300, 200));
- setLayout(null);
- setResizable(false);
- initComponent();
- initEvent();
- }
- private void initComponent() {
- btnSprawdz.setBounds(140, 130, 100, 25);
- btnExit.setBounds(260, 130, 100, 25);
- txtA.setBounds(100, 10, 260, 100);
- lblA.setBounds(20, 10, 100, 20);
- add(btnSprawdz);
- add(btnExit);
- add(lblA);
- add(txtA);
- txtA.setLineWrap(true);
- txtA.setWrapStyleWord(true);
- }
- private void initEvent() {
- this.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.exit(1);
- }
- });
- btnExit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- btnExit(e);
- }
- });
- btnSprawdz.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- btnTutupClick(e);
- }
- });
- }
- private void btnTutupClick(ActionEvent evt) {
- try {
- String lancuch = txtA.getText().toLowerCase();
- String slowo[] = lancuch.split("[\\p{Punct}\\s+]");
- for (int i = 0; i < slowo.length; i++) {
- int licznik = 0;
- wyjscie = 0;
- for (int j = 0; j < slowo.length; j++) {
- if (slowo[i].equals(slowo[j])) {
- if (j < i) {
- break;
- }
- licznik++;
- }
- }
- if (licznik > 1) {
- JOptionPane.showMessageDialog(null, "True");
- wyjscie = licznik;
- break;
- }
- }
- if (wyjscie <= 1 && wyjscie == 0){
- JOptionPane.showMessageDialog(null, "False");
- return;
- }
- } catch (Exception e) {
- System.out.println(e);
- JOptionPane.showMessageDialog(null, e.toString(), "Błąd", JOptionPane.ERROR_MESSAGE);
- }
- }
- private void btnExit(ActionEvent evt) {
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement