Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class GraphicClass extends JFrame implements ActionListener {
- private JTextArea textArea;
- private JButton b1, b2, b3, b4;
- private JPanel pane;
- private JLabel label;
- private TextClass textClass;
- private String input;
- public GraphicClass() {
- super("INTERFACE PLUS MOINS");
- pane = new JPanel();
- pane.setLayout(new GridLayout(3, 2));
- textArea = new JTextArea("enter text here");
- label = new JLabel("Result: ");
- b1 = new JButton("numb of chars.");
- b1.addActionListener(this::actionPerformed);
- b2 = new JButton("numb of words");
- b2.addActionListener(this::actionPerformed);
- b3 = new JButton("numb of sentences");
- b3.addActionListener(this::actionPerformed);
- b4 = new JButton("contains Word?");
- b4.addActionListener(this::actionPerformed);
- pane.add(textArea);
- pane.add(label);
- pane.add(b1);
- pane.add(b2);
- pane.add(b3);
- pane.add(b4);
- pane.setSize(new Dimension(400, 250));
- setContentPane(pane);
- pack();
- this.setLocationRelativeTo(null);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setVisible(true);
- }
- public static void main(String[] args) {
- GraphicClass test = new GraphicClass();
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- textClass = new TextClass();
- input = textArea.getText();
- if (e.getSource() == b1) {
- label.setText("Result: " + textClass.numberOfCharacters(input));
- } else if (e.getSource() == b2) {
- label.setText("Result: " + textClass.numberOfWords(input));
- } else if (e.getSource() == b3) {
- label.setText("Result: " + textClass.numberOfSentences(input));
- } else if (e.getSource() == b4) {
- String word = JOptionPane.showInputDialog(this, "Word your looking for:");
- label.setText("Result: " + textClass.doesWordExist(word, input));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment