Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- class Strumienie extends JFrame implements ActionListener {
- JButton read, save1;
- TextArea textArea;
- JPanel panel;
- Strumienie(){
- super("Strumienie");
- setBounds(100,100,300,300);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- panel = new JPanel(null);
- panel.setBackground(Color.GREEN);
- read = new JButton("Odczytaj");
- save1 = new JButton("Zapisz");
- textArea = new TextArea();
- read.setBounds(20,200,100,25);
- read.addActionListener(this);
- save1.setBounds(160,200,100,25);
- save1.addActionListener(this);
- textArea.setBounds(20,50,240,100);
- panel.add(read);
- panel.add(save1);
- panel.add(textArea);
- setContentPane(panel);
- setVisible(true);
- }
- public void actionPerformed(ActionEvent e) {
- Object ob = e.getSource();
- if(ob==save1){
- try {
- panel.setBackground(Color.CYAN);
- FileWriter plik = new FileWriter("tekst123.txt");
- plik.write(textArea.getText());
- plik.close();
- }
- catch(IOException x){
- textArea.setText("Err0r!@#"+x.toString());
- }
- }
- if(ob==read){
- try {
- panel.setBackground(Color.YELLOW);
- FileReader plik = new FileReader("tekst123.txt");
- BufferedReader bufor = new BufferedReader(plik);
- String line = bufor.readLine();
- textArea.setText(line+"\n");
- }
- catch(IOException x) {
- textArea.setText("Err0r!@#"+x.toString());
- }
- }
- }
- public static void main (String arg[]){
- new Strumienie();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement