Darano

GraphicClass.java

Dec 2nd, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6.  
  7. public class GraphicClass extends JFrame implements ActionListener {
  8.  
  9.     private JTextArea textArea;
  10.     private JButton b1, b2, b3, b4;
  11.     private JPanel pane;
  12.     private JLabel label;
  13.     private TextClass textClass;
  14.     private String input;
  15.  
  16.     public GraphicClass() {
  17.         super("INTERFACE PLUS MOINS");
  18.         pane = new JPanel();
  19.         pane.setLayout(new GridLayout(3, 2));
  20.         textArea = new JTextArea("enter text here");
  21.         label = new JLabel("Result: ");
  22.  
  23.         b1 = new JButton("numb of chars.");
  24.         b1.addActionListener(this::actionPerformed);
  25.         b2 = new JButton("numb of words");
  26.         b2.addActionListener(this::actionPerformed);
  27.         b3 = new JButton("numb of sentences");
  28.         b3.addActionListener(this::actionPerformed);
  29.         b4 = new JButton("contains Word?");
  30.         b4.addActionListener(this::actionPerformed);
  31.  
  32.         pane.add(textArea);
  33.         pane.add(label);
  34.         pane.add(b1);
  35.         pane.add(b2);
  36.         pane.add(b3);
  37.         pane.add(b4);
  38.         pane.setSize(new Dimension(400, 250));
  39.         setContentPane(pane);
  40.         pack();
  41.         this.setLocationRelativeTo(null);
  42.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  43.         this.setVisible(true);
  44.  
  45.  
  46.     }
  47.  
  48.     public static void main(String[] args) {
  49.         GraphicClass test = new GraphicClass();
  50.  
  51.     }
  52.  
  53.     @Override
  54.     public void actionPerformed(ActionEvent e) {
  55.         textClass = new TextClass();
  56.         input = textArea.getText();
  57.  
  58.         if (e.getSource() == b1) {
  59.             label.setText("Result: " + textClass.numberOfCharacters(input));
  60.         } else if (e.getSource() == b2) {
  61.             label.setText("Result: " + textClass.numberOfWords(input));
  62.         } else if (e.getSource() == b3) {
  63.             label.setText("Result: " + textClass.numberOfSentences(input));
  64.         } else if (e.getSource() == b4) {
  65.             String word = JOptionPane.showInputDialog(this, "Word your looking for:");
  66.             label.setText("Result: " + textClass.doesWordExist(word, input));
  67.         }
  68.  
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment