Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.event.*;
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.StringTokenizer;
- import javax.swing.*;
- public class Słownik12 extends JFrame implements ActionListener {
- String i;
- JButton przycisk;
- JLabel etykieta1, etykieta2;
- JTextField tekstPA, tekstAP;
- HashMap<String, String> value = new HashMap<String, String>();
- public Słownik12() throws FileNotFoundException, IOException {
- setSize(400, 400); //rozmiar ramki
- setTitle("SŁOWNIK ANG-POL & POL-ANG"); //tytuł
- setLayout(null);
- przycisk = new JButton("Tłumacz");
- przycisk.setBounds(150, 160, 100, 60);//polozenie przycisku
- add(przycisk);//dodanie przycisku
- przycisk.addActionListener(this); //słuchaczem jest cała ramka
- etykieta1 = new JLabel("ang");
- etykieta1.setBounds(100, 100, 70, 60);
- etykieta1.setForeground(Color.BLUE);
- //add(etykieta1);
- tekstAP = new JTextField();
- tekstAP.setBounds(150, 100, 100, 40);
- tekstAP.setEnabled(false);
- add(tekstAP);
- etykieta2 = new JLabel("pol");
- etykieta2.setBounds(100, 50, 70, 60);
- etykieta2.setForeground(Color.BLUE);
- //add(etykieta2);
- tekstPA = new JTextField();
- tekstPA.setBounds(150, 50, 100, 40);
- add(tekstPA);
- FileReader fr = new FileReader(System.getProperty("user.home") + "\\Desktop\\slownik.txt");
- BufferedReader br = new BufferedReader(fr);
- String s;
- while ((s = br.readLine()) != null) //odczytanie kolejnych linijek pliku
- {
- StringTokenizer st = new StringTokenizer(s, ",");
- while(st.hasMoreTokens())
- {
- String key = st.nextToken();
- String val = st.nextToken();
- value.put(key,val) ;
- value.put(val,key);
- }
- }
- System.out.println(value);
- fr.close();
- }
- public static void main(String[] args) throws FileNotFoundException, IOException {
- Słownik12 slownik = new Słownik12();
- slownik.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //zamyka okienko krzyzykiem
- slownik.setVisible(true); // wyswietli ramke
- }
- @Override
- public void actionPerformed(ActionEvent e) //obiekt zdarzenia, który jest wysyłany przez przycisk do słuchacza
- {
- if (e.getSource() == przycisk) {
- tekstAP.setText(value.get(tekstPA.getText()));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement