Advertisement
cr34tiv3

[JAVA] Morse Decoder GUI (German)

Jan 16th, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.03 KB | None | 0 0
  1. import javax.swing.JButton;
  2. import javax.swing.JFrame;
  3. import javax.swing.JLabel;
  4. import javax.swing.JProgressBar;
  5. import javax.swing.JTextField;
  6.  
  7. //import Program1.btnDoAction;
  8. //import Program1.thread1;
  9.  
  10. import java.awt.event.*;
  11. import java.awt.*;
  12. import java.util.Random;
  13. import java.io.File;
  14. import java.io.FileWriter;
  15. import java.io.IOException;
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. public class GUI extends JFrame {
  23.    
  24.     JLabel Text = new JLabel("Morsedecoder");
  25.     JTextField Output;
  26.    
  27.     JButton Decode;
  28.     JButton Short;
  29.     JButton Long;
  30.     JButton Clear;
  31.     JButton Save;
  32.    
  33.     JLabel Comp;
  34.    
  35.     String temp1="";
  36.     String comp="";
  37.    
  38.     Queue Morse;
  39.    
  40.     int out=0;
  41.    
  42.     BinaryTree baum0;
  43.     BinaryTree baumA;
  44.     BinaryTree baumB;
  45.     BinaryTree baumC;
  46.     BinaryTree baumD;
  47.     BinaryTree baumE;
  48.     BinaryTree baumF;
  49.     BinaryTree baumG;
  50.     BinaryTree baumH;
  51.     BinaryTree baumI;
  52.     BinaryTree baumJ;
  53.     BinaryTree baumK;
  54.     BinaryTree baumL;
  55.     BinaryTree baumM;
  56.     BinaryTree baumN;
  57.     BinaryTree baumO;
  58.     BinaryTree baumP;
  59.     BinaryTree baumQ;
  60.     BinaryTree baumR;
  61.     BinaryTree baumS;
  62.     BinaryTree baumT;
  63.     BinaryTree baumU;
  64.     BinaryTree baumV;
  65.     BinaryTree baumW;
  66.     BinaryTree baumX;
  67.     BinaryTree baumY;  
  68.     BinaryTree baumZ;
  69.     BinaryTree baumÜ;
  70.     BinaryTree baumCH;
  71.     BinaryTree baumÖ;
  72.     BinaryTree baumÄ;
  73.    
  74.     public GUI()
  75.     {
  76.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  77.         setSize(380, 300);
  78.         setTitle("Morsedecoder");
  79.         setLayout(null);
  80.         setLocationRelativeTo(null);
  81.        
  82.         Decode = new JButton("Decode");
  83.         Decode.setBounds(10,100,150,30);
  84.         Decode.addActionListener(new UnserListener());
  85.         add(Decode);
  86.        
  87.         Clear = new JButton ("Clear");
  88.         Clear.setBounds(10,150,150,30);
  89.         Clear.addActionListener(new UnserListener());
  90.         add(Clear);
  91.        
  92.         Short = new JButton("Morse - kurz");
  93.         Short.setBounds(200,100,150,30);
  94.         Short.addActionListener(new UnserListener());
  95.         add(Short);
  96.        
  97.         Long = new JButton("Morse - long");
  98.         Long.setBounds(200,150,150,30);
  99.         Long.addActionListener(new UnserListener());
  100.         add(Long);
  101.        
  102.         Save = new JButton("Wort speichern");
  103.         Save.setBounds(50,200, 300, 30);
  104.         Save.addActionListener(new UnserListener());
  105.         add(Save);
  106.        
  107.         Comp = new JLabel("");
  108.         Comp.setBounds(50, 235, 300, 30);
  109.         add(Comp);
  110.        
  111.         Output = new JTextField("");
  112.         Output.setBounds(10, 50, 350,   30);
  113.         Output.addActionListener(new UnserListener());
  114.         add(Output);
  115.        
  116.         Text.setBounds(10,20, 150, 30);
  117.         add(Text);
  118.         baumB = new BinaryTree("B");
  119.         baumX = new BinaryTree("X");
  120.         baumC = new BinaryTree("C");
  121.         baumY = new BinaryTree("Y");
  122.         baumQ = new BinaryTree("Q");
  123.         baumZ = new BinaryTree("Z");
  124.         baumÖ = new BinaryTree("Ö");
  125.         baumCH = new BinaryTree("CH");
  126.         baumO = new BinaryTree("O",baumÖ,baumCH);
  127.         baumG = new BinaryTree("G",baumZ,baumQ);
  128.         baumK = new BinaryTree("K",baumC,baumY);
  129.         baumD = new BinaryTree("D",baumB,baumX);
  130.         baumM = new BinaryTree("M",baumG,baumO);
  131.         baumN = new BinaryTree("N",baumD,baumK);
  132.         baumT = new BinaryTree("T",baumN,baumM);
  133.         baumÜ = new BinaryTree("Ü");
  134.         baumL = new BinaryTree("L");
  135.         baumÄ = new BinaryTree("Ä");
  136.         baumP = new BinaryTree("P");
  137.         baumJ = new BinaryTree("J");
  138.         baumF = new BinaryTree("F");
  139.         baumV = new BinaryTree("V");
  140.         baumH = new BinaryTree("H");
  141.         baumW = new BinaryTree("W", baumP, baumJ);
  142.         baumR = new BinaryTree("R", baumL, baumÄ);
  143.         baumU = new BinaryTree("U", baumF, baumÜ);
  144.         baumS = new BinaryTree("S", baumH, baumV);
  145.         baumA = new BinaryTree("A", baumR, baumW);
  146.         baumI = new BinaryTree("I", baumS, baumU);
  147.         baumE = new BinaryTree("E", baumI, baumA);
  148.         baum0 = new BinaryTree(0, baumE, baumT);           
  149.         Morse = new Queue();
  150.        
  151.     }
  152.    
  153.     public class UnserListener implements ActionListener
  154.     {
  155.  
  156.          public void actionPerformed(ActionEvent arg0)
  157.          {
  158.              
  159.             if(arg0.getSource()==Short)
  160.             {
  161.                
  162.                 Morse.enqueue(0);
  163.                
  164.             }
  165.            
  166.             if(arg0.getSource()==Long)
  167.             {
  168.                
  169.                 Morse.enqueue(1);
  170.             }
  171.            
  172.             if(arg0.getSource()==Clear)
  173.             {
  174.                 while(!Morse.isEmpty())
  175.                 {
  176.                     Morse.dequeue();
  177.                 }
  178.                 Output.setText(null);
  179.                 temp1="";
  180.                
  181.             }
  182.            
  183.             if(arg0.getSource()==Decode)
  184.             {
  185.                 rechner(baum0);
  186.                 while(!Morse.isEmpty())
  187.                 {
  188.                     Morse.dequeue();
  189.                 }
  190.             }
  191.            
  192.             if(arg0.getSource()==Save)
  193.             {
  194.                 Output.setText("");
  195.                 comp=comp+" "+temp1;
  196.                 Comp.setText(comp);
  197.                 temp1="";
  198.                 while(!Morse.isEmpty())
  199.                 {
  200.                     Morse.dequeue();
  201.                 }
  202.                
  203.             }
  204.              
  205.          }
  206.          
  207.     }
  208.    
  209.     public void rechner(BinaryTree pTree)
  210.     {
  211.        
  212.         if(!Morse.isEmpty() && pTree.getObject()!=null)
  213.         {
  214.             int temp = (Integer)Morse.front();
  215.             if(temp==0)
  216.             {
  217.                 Morse.dequeue();
  218.                 rechner(pTree.getLeftTree());
  219.                
  220.             }
  221.             else if(temp==1)
  222.             {
  223.                 Morse.dequeue();
  224.                 rechner(pTree.getRightTree());
  225.                
  226.             }
  227.         }
  228.        
  229.         else if(Morse.isEmpty() && pTree.getObject()!=null)
  230.         {          
  231.             temp1 = temp1 + "" + pTree.getObject();
  232.             Output.setText(temp1);
  233.         }
  234.        
  235.         else if(pTree.getObject()==null)
  236.         {
  237.             while(!Morse.isEmpty())
  238.             {
  239.                 Morse.dequeue();
  240.             }
  241.             Output.setText("Bitte richtiges Morse eingeben");
  242.            
  243.         }
  244.     }
  245.    
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement