Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JProgressBar;
- import javax.swing.JTextField;
- //import Program1.btnDoAction;
- //import Program1.thread1;
- import java.awt.event.*;
- import java.awt.*;
- import java.util.Random;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- public class GUI extends JFrame {
- JLabel Text = new JLabel("Morsedecoder");
- JTextField Output;
- JTextField Input;
- JButton Decode;
- JButton Short;
- JButton Long;
- JButton Clear;
- JButton Save;
- JButton Switch;
- JLabel Comp;
- String temp1="";
- String comp="";
- String input="";
- Queue Morse;
- int out=0;
- int count=0;
- BinaryTree baum0;
- BinaryTree baumA;
- BinaryTree baumB;
- BinaryTree baumC;
- BinaryTree baumD;
- BinaryTree baumE;
- BinaryTree baumF;
- BinaryTree baumG;
- BinaryTree baumH;
- BinaryTree baumI;
- BinaryTree baumJ;
- BinaryTree baumK;
- BinaryTree baumL;
- BinaryTree baumM;
- BinaryTree baumN;
- BinaryTree baumO;
- BinaryTree baumP;
- BinaryTree baumQ;
- BinaryTree baumR;
- BinaryTree baumS;
- BinaryTree baumT;
- BinaryTree baumU;
- BinaryTree baumV;
- BinaryTree baumW;
- BinaryTree baumX;
- BinaryTree baumY;
- BinaryTree baumZ;
- BinaryTree baumÜ;
- BinaryTree baumCH;
- BinaryTree baumÖ;
- BinaryTree baumÄ;
- public GUI()
- {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setSize(380, 300);
- setTitle("Morsedecoder");
- setLayout(null);
- setLocationRelativeTo(null);
- Input = new JTextField("Bitte hier Morse eingeben.");
- Input.setBounds(10,100,350,30);
- Input.addActionListener(new UnserListener());
- Input.setVisible(false);
- add(Input);
- Decode = new JButton("Decode");
- Decode.setBounds(200,150,150,30);
- Decode.addActionListener(new UnserListener());
- add(Decode);
- Switch = new JButton ("S");
- Switch.setBounds(300,5,50,30);
- Switch.addActionListener(new UnserListener());
- add(Switch);
- Clear = new JButton ("Clear");
- Clear.setBounds(10,150,150,30);
- Clear.addActionListener(new UnserListener());
- add(Clear);
- Short = new JButton("Morse - kurz");
- Short.setBounds(10,100,150,30);
- Short.addActionListener(new UnserListener());
- add(Short);
- Long = new JButton("Morse - long");
- Long.setBounds(200,100,150,30);
- Long.addActionListener(new UnserListener());
- add(Long);
- Save = new JButton("Wort speichern");
- Save.setBounds(50,200, 300, 30);
- Save.addActionListener(new UnserListener());
- add(Save);
- Comp = new JLabel("");
- Comp.setBounds(50, 235, 300, 30);
- add(Comp);
- Output = new JTextField("");
- Output.setBounds(10, 50, 350, 30);
- Output.addActionListener(new UnserListener());
- add(Output);
- Text.setBounds(10,20, 150, 30);
- add(Text);
- baumB = new BinaryTree("B");
- baumX = new BinaryTree("X");
- baumC = new BinaryTree("C");
- baumY = new BinaryTree("Y");
- baumQ = new BinaryTree("Q");
- baumZ = new BinaryTree("Z");
- baumÖ = new BinaryTree("Ö");
- baumCH = new BinaryTree("CH");
- baumO = new BinaryTree("O",baumÖ,baumCH);
- baumG = new BinaryTree("G",baumZ,baumQ);
- baumK = new BinaryTree("K",baumC,baumY);
- baumD = new BinaryTree("D",baumB,baumX);
- baumM = new BinaryTree("M",baumG,baumO);
- baumN = new BinaryTree("N",baumD,baumK);
- baumT = new BinaryTree("T",baumN,baumM);
- baumÜ = new BinaryTree("Ü");
- baumL = new BinaryTree("L");
- baumÄ = new BinaryTree("Ä");
- baumP = new BinaryTree("P");
- baumJ = new BinaryTree("J");
- baumF = new BinaryTree("F");
- baumV = new BinaryTree("V");
- baumH = new BinaryTree("H");
- baumW = new BinaryTree("W", baumP, baumJ);
- baumR = new BinaryTree("R", baumL, baumÄ);
- baumU = new BinaryTree("U", baumF, baumÜ);
- baumS = new BinaryTree("S", baumH, baumV);
- baumA = new BinaryTree("A", baumR, baumW);
- baumI = new BinaryTree("I", baumS, baumU);
- baumE = new BinaryTree("E", baumI, baumA);
- baum0 = new BinaryTree(0, baumE, baumT);
- Morse = new Queue();
- }
- public class UnserListener implements ActionListener
- {
- public void actionPerformed(ActionEvent arg0)
- {
- if(arg0.getSource()==Short)
- {
- count=0;
- Morse.enqueue(0);
- }
- if(arg0.getSource()==Long)
- {
- count=0;
- Morse.enqueue(1);
- }
- if(arg0.getSource()==Clear)
- {
- count=count+1;
- if(count==2)
- {
- Comp.setText("");
- comp="";
- }
- while(!Morse.isEmpty())
- {
- Morse.dequeue();
- }
- Output.setText(null);
- temp1="";
- }
- if(arg0.getSource()==Decode)
- {
- count=0;
- rechner(baum0);
- while(!Morse.isEmpty())
- {
- Morse.dequeue();
- }
- }
- if(arg0.getSource()==Save)
- {
- Output.setText("");
- comp=comp+" "+temp1;
- Comp.setText(comp);
- temp1="";
- while(!Morse.isEmpty())
- {
- Morse.dequeue();
- }
- }
- if(arg0.getSource()==Switch)
- {
- Short.setVisible(false);
- Long.setVisible(false);
- Input.setVisible(true);
- }
- }
- }
- public void rechner(BinaryTree pTree)
- {
- if(!Morse.isEmpty() && pTree.getObject()!=null)
- {
- int temp = (Integer)Morse.front();
- if(temp==0)
- {
- Morse.dequeue();
- rechner(pTree.getLeftTree());
- }
- else if(temp==1)
- {
- Morse.dequeue();
- rechner(pTree.getRightTree());
- }
- }
- else if(Morse.isEmpty() && pTree.getObject()!=null)
- {
- temp1 = temp1 + "" + pTree.getObject();
- Output.setText(temp1);
- }
- else if(pTree.getObject()==null)
- {
- while(!Morse.isEmpty())
- {
- Morse.dequeue();
- }
- Output.setText("Bitte richtiges Morse eingeben");
- }
- }
- public void einlesen()
- {
- input=Input.getText();
- String[] input2=input.split(" ");
- for(int i=0, i<4, i++)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement