Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.cheesekeg.wordcount.gui;
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import com.cheesekeg.wordcount.WordCount;
- /**
- * @author Brandon DeRosier
- * @since 0.1
- * @version 0.1
- */
- public class WordCountWindow extends JFrame {
- private static final long serialVersionUID = 1L;
- private JLabel inputLabel, outputLabel;
- private JTextArea inputArea, outputArea;
- private JButton button;
- /**
- * Construct a new WordCountWindow.
- */
- public WordCountWindow() {
- populateGUI();
- //pack(); // Automatically size the window.
- addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- });
- setVisible(true); // Make the window visible.
- }
- /**
- * Initialize and apply elements to the window.
- */
- private void populateGUI() {
- setResizable(false);
- setSize(590, 570);
- setLayout(new FlowLayout());
- // Initialize the labels.
- inputLabel = new JLabel("Input:", JLabel.CENTER);
- outputLabel = new JLabel("Output:", JLabel.CENTER);
- // Initialize the TextAreas
- inputArea = new JTextArea(15, 50);
- outputArea = new JTextArea(15, 50);
- inputArea.setEditable(true);
- outputArea.setEditable(false);
- // Initialize scroll panes to encapsulate the text areas.
- JScrollPane inputScrollPane = new JScrollPane(inputArea,
- JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
- JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
- JScrollPane outputScrollPane = new JScrollPane(outputArea,
- JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
- JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
- // Initialize the button.
- button = new JButton("Sort by frequency");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.out.println("Sorting button pressed!");
- outputArea.setText(WordCount.CountWordString(inputArea.getText()));
- }
- });
- // Add the elements to the window.
- add(inputLabel);
- add(inputScrollPane);
- add(outputLabel);
- add(outputScrollPane);
- add(button);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement