Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.event.*;
  4. import javax.swing.*;
  5. import javax.swing.text.*;
  6. import javax.swing.border.*;
  7. import java.util.*;
  8.  
  9.  
  10.  
  11. public class CipherCasearGUI_MVC {
  12.  
  13.  
  14. public static void main(String args[]) {
  15. try {
  16. UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
  17. } catch (Exception e) {}
  18. JFrame cipherGUIFrame = new CipherGUIFrame();
  19. cipherGUIFrame.setVisible(true);
  20.  
  21. }
  22. }
  23.  
  24. class CipherGUIFrame extends JFrame{
  25. public CipherGUIFrame() {
  26. super("Caesar Cipher GUI-- Courtney Ball");
  27. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  28. setSize(400, 600);
  29. Container content = getContentPane();
  30. content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
  31.  
  32.  
  33.  
  34.  
  35. JTextArea clearTextInput;
  36. JTextArea IOText;
  37.  
  38. Color tmp = this.getBackground();
  39.  
  40.  
  41.  
  42. //-----------------------Cleartext Area Jtextarea------------------------------
  43. DocumentListener cleartextListener = new DocumentListener(){
  44. public void insertUpdate(DocumentEvent e){
  45. System.out.println("Text is working");
  46. }
  47. public void changedUpdate(DocumentEvent e){
  48. System.out.println("Text2 is working");
  49. }
  50. public void removeUpdate(DocumentEvent e){
  51. System.out.println("Text 3 is working");
  52. }
  53. } ;
  54. clearTextInput = new JTextArea(5, 10);
  55. clearTextInput.setAlignmentX(Component.LEFT_ALIGNMENT);
  56. clearTextInput.setBackground(tmp);
  57. clearTextInput.setBorder(new TitledBorder(new EtchedBorder(),
  58. "Clear Text Input"));
  59. clearTextInput.getDocument().addDocumentListener(cleartextListener);
  60. content.add(clearTextInput);
  61.  
  62. //-----------------------------------------------------------------------------------------------
  63. JSpinner spinner = new JSpinner(new SpinnerNumberModel(0, 0, 25, 1)) {
  64. //numModel = new SpinnerNumberModel(0, 0, 25, 1);
  65. public Object getNextValue() {
  66. Object returnValue = super.getNextValue();
  67. if(returnValue == null) {
  68. returnValue = ((SpinnerNumberModel) super.getModel()).getMinimum();
  69. }
  70. return returnValue;
  71. }
  72. public Object getPreviousValue() {
  73. Object returnValue = super.getPreviousValue();
  74. if(returnValue == null) {
  75. returnValue = ((SpinnerNumberModel) super.getModel()).getMaximum();
  76. }
  77. return returnValue;
  78. }
  79. };
  80.  
  81. //----------------------JSPinner------------------------------------------
  82. ChangeListener spin = new ChangeListener(){
  83. public void stateChanged(ChangeEvent e){
  84. System.out.println("Spinner is working");
  85. }
  86. };
  87.  
  88. spinner.setBackground(tmp);
  89. spinner.setSize(100,100);
  90. spinner.setBorder(new TitledBorder(new EtchedBorder(),
  91. "Key"));
  92. spinner.addChangeListener(spin);
  93. content.add(spinner);
  94. //--------------------------------------------------------------------------
  95.  
  96.  
  97. //---------------------TOGGLE BUTTON-----------------------------------------
  98. ActionListener toggle = new ActionListener(){
  99. public void actionPerformed(ActionEvent e){
  100. if(button.isSelected()){
  101. clearTextInput.setEnabled(false);
  102. IOText.setEnabled(true);
  103. }
  104. else{
  105. clearTextInput.setEnabled(true);
  106. IOText.setEnabled(false);
  107. }
  108. }
  109.  
  110. };
  111.  
  112. JToggleButton button = new JToggleButton("Decrypt");
  113. button.addActionListener(toggle);
  114. content.add(button);
  115.  
  116.  
  117. //--------------------------------------------------------------------------
  118.  
  119.  
  120.  
  121. //-------------------JTextArea--------------------------------
  122. DocumentListener text = new DocumentListener(){
  123. public void insertUpdate(DocumentEvent e){
  124. System.out.println("Text is working");
  125. }
  126. public void changedUpdate(DocumentEvent e){
  127. System.out.println("Text2 is working");
  128. }
  129. public void removeUpdate(DocumentEvent e){
  130. System.out.println("Text 3 is working");
  131. }
  132. } ;
  133.  
  134. IOText = new JTextArea(5, 10);
  135. IOText.setAlignmentX(Component.LEFT_ALIGNMENT);
  136. IOText.setBackground(tmp);
  137. IOText.setBorder(new TitledBorder(new EtchedBorder(),
  138. "Cipher Text Input/Output"));
  139. IOText.getDocument().addDocumentListener(text);
  140. content.add(IOText);
  141.  
  142.  
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement