Advertisement
cr34tiv3

-

Jan 17th, 2013
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.82 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. JTextField Input;
  27.  
  28. JButton Decode;
  29. JButton Short;
  30. JButton Long;
  31. JButton Clear;
  32. JButton Save;
  33. JButton Switch;
  34.  
  35. JLabel Comp;
  36.  
  37. String temp1="";
  38. String comp="";
  39. String input="";
  40.  
  41.  
  42. Queue Morse;
  43.  
  44. int out=0;
  45. int count=0;
  46.  
  47. BinaryTree baum0;
  48. BinaryTree baumA;
  49. BinaryTree baumB;
  50. BinaryTree baumC;
  51. BinaryTree baumD;
  52. BinaryTree baumE;
  53. BinaryTree baumF;
  54. BinaryTree baumG;
  55. BinaryTree baumH;
  56. BinaryTree baumI;
  57. BinaryTree baumJ;
  58. BinaryTree baumK;
  59. BinaryTree baumL;
  60. BinaryTree baumM;
  61. BinaryTree baumN;
  62. BinaryTree baumO;
  63. BinaryTree baumP;
  64. BinaryTree baumQ;
  65. BinaryTree baumR;
  66. BinaryTree baumS;
  67. BinaryTree baumT;
  68. BinaryTree baumU;
  69. BinaryTree baumV;
  70. BinaryTree baumW;
  71. BinaryTree baumX;
  72. BinaryTree baumY;
  73. BinaryTree baumZ;
  74. BinaryTree baumÜ;
  75. BinaryTree baumCH;
  76. BinaryTree baumÖ;
  77. BinaryTree baumÄ;
  78.  
  79. public GUI()
  80. {
  81. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  82. setSize(380, 300);
  83. setTitle("Morsedecoder");
  84. setLayout(null);
  85. setLocationRelativeTo(null);
  86.  
  87. Input = new JTextField("Bitte hier Morse eingeben.");
  88. Input.setBounds(10,100,350,30);
  89. Input.addActionListener(new UnserListener());
  90. Input.setVisible(false);
  91. add(Input);
  92.  
  93. Decode = new JButton("Decode");
  94. Decode.setBounds(200,150,150,30);
  95. Decode.addActionListener(new UnserListener());
  96. add(Decode);
  97.  
  98. Switch = new JButton ("S");
  99. Switch.setBounds(300,5,50,30);
  100. Switch.addActionListener(new UnserListener());
  101. add(Switch);
  102.  
  103. Clear = new JButton ("Clear");
  104. Clear.setBounds(10,150,150,30);
  105. Clear.addActionListener(new UnserListener());
  106. add(Clear);
  107.  
  108. Short = new JButton("Morse - kurz");
  109. Short.setBounds(10,100,150,30);
  110. Short.addActionListener(new UnserListener());
  111. add(Short);
  112.  
  113. Long = new JButton("Morse - long");
  114. Long.setBounds(200,100,150,30);
  115. Long.addActionListener(new UnserListener());
  116. add(Long);
  117.  
  118. Save = new JButton("Wort speichern");
  119. Save.setBounds(50,200, 300, 30);
  120. Save.addActionListener(new UnserListener());
  121. add(Save);
  122.  
  123. Comp = new JLabel("");
  124. Comp.setBounds(50, 235, 300, 30);
  125. add(Comp);
  126.  
  127. Output = new JTextField("");
  128. Output.setBounds(10, 50, 350, 30);
  129. Output.addActionListener(new UnserListener());
  130. add(Output);
  131.  
  132. Text.setBounds(10,20, 150, 30);
  133. add(Text);
  134. baumB = new BinaryTree("B");
  135. baumX = new BinaryTree("X");
  136. baumC = new BinaryTree("C");
  137. baumY = new BinaryTree("Y");
  138. baumQ = new BinaryTree("Q");
  139. baumZ = new BinaryTree("Z");
  140. baumÖ = new BinaryTree("Ö");
  141. baumCH = new BinaryTree("CH");
  142. baumO = new BinaryTree("O",baumÖ,baumCH);
  143. baumG = new BinaryTree("G",baumZ,baumQ);
  144. baumK = new BinaryTree("K",baumC,baumY);
  145. baumD = new BinaryTree("D",baumB,baumX);
  146. baumM = new BinaryTree("M",baumG,baumO);
  147. baumN = new BinaryTree("N",baumD,baumK);
  148. baumT = new BinaryTree("T",baumN,baumM);
  149. baumÜ = new BinaryTree("Ü");
  150. baumL = new BinaryTree("L");
  151. baumÄ = new BinaryTree("Ä");
  152. baumP = new BinaryTree("P");
  153. baumJ = new BinaryTree("J");
  154. baumF = new BinaryTree("F");
  155. baumV = new BinaryTree("V");
  156. baumH = new BinaryTree("H");
  157. baumW = new BinaryTree("W", baumP, baumJ);
  158. baumR = new BinaryTree("R", baumL, baumÄ);
  159. baumU = new BinaryTree("U", baumF, baumÜ);
  160. baumS = new BinaryTree("S", baumH, baumV);
  161. baumA = new BinaryTree("A", baumR, baumW);
  162. baumI = new BinaryTree("I", baumS, baumU);
  163. baumE = new BinaryTree("E", baumI, baumA);
  164. baum0 = new BinaryTree(0, baumE, baumT);
  165. Morse = new Queue();
  166.  
  167. }
  168.  
  169. public class UnserListener implements ActionListener
  170. {
  171.  
  172. public void actionPerformed(ActionEvent arg0)
  173. {
  174.  
  175. if(arg0.getSource()==Short)
  176. {
  177. count=0;
  178. Morse.enqueue(0);
  179.  
  180. }
  181.  
  182. if(arg0.getSource()==Long)
  183. {
  184. count=0;
  185. Morse.enqueue(1);
  186. }
  187.  
  188. if(arg0.getSource()==Clear)
  189. {
  190. count=count+1;
  191. if(count==2)
  192. {
  193. Comp.setText("");
  194. comp="";
  195. }
  196. while(!Morse.isEmpty())
  197. {
  198. Morse.dequeue();
  199. }
  200. Output.setText(null);
  201. temp1="";
  202.  
  203. }
  204.  
  205. if(arg0.getSource()==Decode)
  206. {
  207. count=0;
  208. rechner(baum0);
  209. while(!Morse.isEmpty())
  210. {
  211. Morse.dequeue();
  212. }
  213. }
  214.  
  215. if(arg0.getSource()==Save)
  216. {
  217. Output.setText("");
  218. comp=comp+" "+temp1;
  219. Comp.setText(comp);
  220. temp1="";
  221. while(!Morse.isEmpty())
  222. {
  223. Morse.dequeue();
  224. }
  225.  
  226. }
  227.  
  228. if(arg0.getSource()==Switch)
  229. {
  230. Short.setVisible(false);
  231. Long.setVisible(false);
  232. Input.setVisible(true);
  233.  
  234. }
  235.  
  236. }
  237.  
  238. }
  239.  
  240. public void rechner(BinaryTree pTree)
  241. {
  242.  
  243. if(!Morse.isEmpty() && pTree.getObject()!=null)
  244. {
  245. int temp = (Integer)Morse.front();
  246. if(temp==0)
  247. {
  248. Morse.dequeue();
  249. rechner(pTree.getLeftTree());
  250.  
  251. }
  252. else if(temp==1)
  253. {
  254. Morse.dequeue();
  255. rechner(pTree.getRightTree());
  256.  
  257. }
  258. }
  259.  
  260. else if(Morse.isEmpty() && pTree.getObject()!=null)
  261. {
  262. temp1 = temp1 + "" + pTree.getObject();
  263. Output.setText(temp1);
  264. }
  265.  
  266. else if(pTree.getObject()==null)
  267. {
  268. while(!Morse.isEmpty())
  269. {
  270. Morse.dequeue();
  271. }
  272. Output.setText("Bitte richtiges Morse eingeben");
  273.  
  274. }
  275. }
  276.  
  277. public void einlesen()
  278. {
  279. input=Input.getText();
  280. String[] input2=input.split(" ");
  281. for(int i=0, i<4, i++)
  282. {
  283.  
  284. }
  285.  
  286. }
  287.  
  288. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement