Advertisement
cr34tiv3

[JAVA]Test

Jan 16th, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.37 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.    
  32.     String temp1="";
  33.    
  34.     Queue Morse;
  35.    
  36.     int out=0;
  37.    
  38.     BinaryTree baum0;
  39.     BinaryTree baumA;
  40.     BinaryTree baumB;
  41.     BinaryTree baumC;
  42.     BinaryTree baumD;
  43.     BinaryTree baumE;
  44.     BinaryTree baumF;
  45.     BinaryTree baumG;
  46.     BinaryTree baumH;
  47.     BinaryTree baumI;
  48.     BinaryTree baumJ;
  49.     BinaryTree baumK;
  50.     BinaryTree baumL;
  51.     BinaryTree baumM;
  52.     BinaryTree baumN;
  53.     BinaryTree baumO;
  54.     BinaryTree baumP;
  55.     BinaryTree baumQ;
  56.     BinaryTree baumR;
  57.     BinaryTree baumS;
  58.     BinaryTree baumT;
  59.     BinaryTree baumU;
  60.     BinaryTree baumV;
  61.     BinaryTree baumW;
  62.     BinaryTree baumX;
  63.     BinaryTree baumY;  
  64.     BinaryTree baumZ;
  65.     BinaryTree baumÜ;
  66.     BinaryTree baumCH;
  67.     BinaryTree baumÖ;
  68.     BinaryTree baumÄ;
  69.    
  70.     public GUI()
  71.     {
  72.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  73.         setSize(380, 300);
  74.         setTitle("Morsedecoder");
  75.         setLayout(null);
  76.         setLocationRelativeTo(null);
  77.        
  78.         Decode = new JButton("Decode");
  79.         Decode.setBounds(10,100,150,30);
  80.         Decode.addActionListener(new UnserListener());
  81.         add(Decode);
  82.        
  83.         Clear = new JButton ("Clear");
  84.         Clear.setBounds(10,150,150,30);
  85.         Clear.addActionListener(new UnserListener());
  86.         add(Clear);
  87.        
  88.         Short = new JButton("Morse - kurz");
  89.         Short.setBounds(200,100,150,30);
  90.         Short.addActionListener(new UnserListener());
  91.         add(Short);
  92.        
  93.         Long = new JButton("Morse - long");
  94.         Long.setBounds(200,150,150,30);
  95.         Long.addActionListener(new UnserListener());
  96.         add(Long);
  97.        
  98.         Output = new JTextField("");
  99.         Output.setBounds(10, 50, 350,   30);
  100.         Output.addActionListener(new UnserListener());
  101.         add(Output);
  102.        
  103.         Text.setBounds(10,20, 150, 30);
  104.         add(Text);
  105.        
  106.         baum0 = new BinaryTree(0, baumE, baumT);       
  107.         baumE = new BinaryTree("E", baumI, baumA);
  108.         baumI = new BinaryTree("I", baumS, baumU);
  109.         baumA = new BinaryTree("A", baumR, baumW);
  110.         baumS = new BinaryTree("S", baumH, baumV);
  111.         baumU = new BinaryTree("U", baumF, baumÜ);
  112.         baumR = new BinaryTree("R", baumL, baumÄ);
  113.         baumW = new BinaryTree("W", baumP, baumJ);
  114.         baumH = new BinaryTree("H");
  115.         baumV = new BinaryTree("V");
  116.         baumF = new BinaryTree("F");
  117.         baumÜ = new BinaryTree("Ü");
  118.         baumL = new BinaryTree("L");
  119.         baumÄ = new BinaryTree("Ä");
  120.         baumP = new BinaryTree("P");
  121.         baumJ = new BinaryTree("J");         
  122.         baumT = new BinaryTree("T",baumN,baumM);
  123.         baumN = new BinaryTree("N",baumD,baumK);
  124.         baumM = new BinaryTree("M",baumG,baumO);
  125.         baumD = new BinaryTree("D",baumB,baumX);
  126.         baumK = new BinaryTree("K",baumC,baumY);
  127.         baumG = new BinaryTree("G",baumQ,baumZ);
  128.         baumO = new BinaryTree("O",baumÖ,baumCH);
  129.         baumB = new BinaryTree("B");
  130.         baumX = new BinaryTree("X");
  131.         baumC = new BinaryTree("C");
  132.         baumY = new BinaryTree("Y");
  133.         baumQ = new BinaryTree("Q");
  134.         baumZ = new BinaryTree("Z");
  135.         baumÖ = new BinaryTree("Ö");
  136.         baumCH = new BinaryTree("CH");  
  137.         Morse = new Queue();
  138.        
  139.     }
  140.    
  141.     public class UnserListener implements ActionListener
  142.     {
  143.  
  144.          public void actionPerformed(ActionEvent arg0)
  145.          {
  146.              
  147.             if(arg0.getSource()==Short)
  148.             {
  149.                
  150.                 Morse.enqueue(0);
  151.                
  152.             }
  153.            
  154.             if(arg0.getSource()==Long)
  155.             {
  156.                
  157.                 Morse.enqueue(1);
  158.             }
  159.            
  160.             if(arg0.getSource()==Clear)
  161.             {
  162.                 while(!Morse.isEmpty())
  163.                 {
  164.                     Morse.dequeue();
  165.                 }
  166.                 Output.setText(null);
  167.                 temp1="";
  168.                
  169.             }
  170.            
  171.             if(arg0.getSource()==Decode)
  172.             {
  173.                 rechner(baum0);
  174.                 while(!Morse.isEmpty())
  175.                 {
  176.                     Morse.dequeue();
  177.                 }
  178.             }
  179.              
  180.          }
  181.          
  182.     }
  183.    
  184.     public void rechner(BinaryTree pTree)
  185.     {
  186.        
  187.         if(!Morse.isEmpty() && pTree.getObject() != null)
  188.         {
  189.             int temp = (Integer)Morse.front();
  190.             if(temp==0)
  191.             {
  192.                 Morse.dequeue();
  193.                 rechner(pTree.getLeftTree());
  194.                
  195.             }
  196.             else if(temp==1)
  197.             {
  198.                 Morse.dequeue();
  199.                 rechner(pTree.getRightTree());
  200.                
  201.             }
  202.         }
  203.        
  204.         if(Morse.isEmpty())
  205.         {          
  206.             temp1 = temp1 + " " + pTree.getObject();
  207.             Output.setText(temp1);
  208.         }
  209.     }
  210.    
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement