Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.event.*;
- import javax.swing.*;
- import javax.swing.text.*;
- import javax.swing.border.*;
- import java.util.*;
- public class CipherCasearGUI_MVC {
- public static void main(String args[]) {
- try {
- UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
- } catch (Exception e) {}
- JFrame cipherGUIFrame = new CipherGUIFrame();
- cipherGUIFrame.setVisible(true);
- }
- }
- class CipherGUIFrame extends JFrame{
- public CipherGUIFrame() {
- super("Caesar Cipher GUI-- Courtney Ball");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setSize(400, 600);
- Container content = getContentPane();
- content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
- JTextArea clearTextInput;
- JTextArea IOText;
- Color tmp = this.getBackground();
- //-----------------------Cleartext Area Jtextarea------------------------------
- DocumentListener cleartextListener = new DocumentListener(){
- public void insertUpdate(DocumentEvent e){
- System.out.println("Text is working");
- }
- public void changedUpdate(DocumentEvent e){
- System.out.println("Text2 is working");
- }
- public void removeUpdate(DocumentEvent e){
- System.out.println("Text 3 is working");
- }
- } ;
- clearTextInput = new JTextArea(5, 10);
- clearTextInput.setAlignmentX(Component.LEFT_ALIGNMENT);
- clearTextInput.setBackground(tmp);
- clearTextInput.setBorder(new TitledBorder(new EtchedBorder(),
- "Clear Text Input"));
- clearTextInput.getDocument().addDocumentListener(cleartextListener);
- content.add(clearTextInput);
- //-----------------------------------------------------------------------------------------------
- JSpinner spinner = new JSpinner(new SpinnerNumberModel(0, 0, 25, 1)) {
- //numModel = new SpinnerNumberModel(0, 0, 25, 1);
- public Object getNextValue() {
- Object returnValue = super.getNextValue();
- if(returnValue == null) {
- returnValue = ((SpinnerNumberModel) super.getModel()).getMinimum();
- }
- return returnValue;
- }
- public Object getPreviousValue() {
- Object returnValue = super.getPreviousValue();
- if(returnValue == null) {
- returnValue = ((SpinnerNumberModel) super.getModel()).getMaximum();
- }
- return returnValue;
- }
- };
- //----------------------JSPinner------------------------------------------
- ChangeListener spin = new ChangeListener(){
- public void stateChanged(ChangeEvent e){
- System.out.println("Spinner is working");
- }
- };
- spinner.setBackground(tmp);
- spinner.setSize(100,100);
- spinner.setBorder(new TitledBorder(new EtchedBorder(),
- "Key"));
- spinner.addChangeListener(spin);
- content.add(spinner);
- //--------------------------------------------------------------------------
- //---------------------TOGGLE BUTTON-----------------------------------------
- ActionListener toggle = new ActionListener(){
- public void actionPerformed(ActionEvent e){
- if(button.isSelected()){
- clearTextInput.setEnabled(false);
- IOText.setEnabled(true);
- }
- else{
- clearTextInput.setEnabled(true);
- IOText.setEnabled(false);
- }
- }
- };
- JToggleButton button = new JToggleButton("Decrypt");
- button.addActionListener(toggle);
- content.add(button);
- //--------------------------------------------------------------------------
- //-------------------JTextArea--------------------------------
- DocumentListener text = new DocumentListener(){
- public void insertUpdate(DocumentEvent e){
- System.out.println("Text is working");
- }
- public void changedUpdate(DocumentEvent e){
- System.out.println("Text2 is working");
- }
- public void removeUpdate(DocumentEvent e){
- System.out.println("Text 3 is working");
- }
- } ;
- IOText = new JTextArea(5, 10);
- IOText.setAlignmentX(Component.LEFT_ALIGNMENT);
- IOText.setBackground(tmp);
- IOText.setBorder(new TitledBorder(new EtchedBorder(),
- "Cipher Text Input/Output"));
- IOText.getDocument().addDocumentListener(text);
- content.add(IOText);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement