Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package week9;
- import javax.swing.*; //for JFrame, JTextField, JTextArea
- import java.awt.*; //for Container, BorderLayout
- import java.awt.event.*; //for WindowAdapter, ActionListener, ActionEvent
- public class TextGUI extends JFrame {
- private static final int WIDTH = 800;
- private static final int HEIGHT = 500;
- private JLabel infoLabel;
- private JTextField textField;
- private JTextArea textArea;
- private final static String newline = "\n";
- private class EnterAction implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- //StringCompare c = new StringCompare();
- String text = textField.getText();
- if(StringCompare.Compare(text) == true)
- textArea.append(text + newline + "There are repeated characters." + newline);
- else
- textArea.append(text + newline + "There are no repeated characters." + newline);
- textField.selectAll();
- textArea.setCaretPosition(textArea.getDocument().getLength());
- }
- }
- private class WindowDestroyer extends WindowAdapter
- {
- public void windowClosing(WindowEvent e)
- {
- dispose();
- System.exit(0);
- }
- }
- public TextGUI(String windowTitle)
- {
- super(windowTitle);
- setSize(WIDTH, HEIGHT);
- Container c1 = getContentPane();
- c1.setLayout( new BorderLayout());
- textField = new JTextField();
- c1.add(textField, BorderLayout.NORTH);
- textArea = new JTextArea();
- c1.add( textArea, BorderLayout.CENTER);
- textArea.setEditable(false);
- EnterAction myAction = new EnterAction();
- textField.addActionListener(myAction);
- WindowDestroyer myListener = new WindowDestroyer();
- addWindowListener(myListener);
- }
- public static void main(String[] args)
- {
- TextGUI app = new TextGUI("Zzzz");
- app.setVisible(true);
- System.out.println("Finished SimplApp.main()");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement