Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import org.omg.CORBA.portable.OutputStream;
- import org.omg.CORBA_2_3.portable.InputStream;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import java.awt.Color;
- import javax.swing.JTextField;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.awt.event.ActionEvent;
- import java.awt.Toolkit;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import java.awt.Font;
- import java.awt.TextArea;
- import javax.swing.JEditorPane;
- import javax.swing.JFileChooser;
- import java.awt.SystemColor;
- public class Bloknot_v2 extends JFrame {
- //protected static final String = null;
- private JPanel contentPane;
- private JTextField textField;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Bloknot_v2 frame = new Bloknot_v2();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public Bloknot_v2() {
- setFont(new Font("Dialog", Font.PLAIN, 9));
- setTitle("\u041E\u043F\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043B\u044F \u0440\u0430\u0431\u043E\u0442\u044B \u0441 \u0444\u0430\u0439\u043B\u043E\u043C");
- setIconImage(Toolkit.getDefaultToolkit().getImage(Bloknot_v2.class.getResource("/javax/swing/plaf/metal/icons/Inform.gif")));
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 298);
- contentPane = new JPanel();
- contentPane.setBackground(Color.GRAY);
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JButton btnBrowse = new JButton("Browse...");
- btnBrowse.setForeground(SystemColor.controlText);
- btnBrowse.setBackground(Color.LIGHT_GRAY);
- btnBrowse.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- JFileChooser fc = new JFileChooser();
- if( fc.showDialog(fc, "Стартуем!Я сказала Стартуем!") == JFileChooser.APPROVE_OPTION) {
- @SuppressWarnings("unused")
- String f = fc.getSelectedFile().getAbsolutePath();
- File nf = new File(f+".txt");
- }
- }
- });
- btnBrowse.setBounds(10, 201, 111, 23);
- contentPane.add(btnBrowse);
- JLabel label = new JLabel("\u0423\u043A\u0430\u0436\u0438\u0442\u0435 \u043F\u0443\u0442\u044C \u043A \u0444\u0430\u0439\u043B\u0443:");
- label.setBounds(10, 11, 355, 14);
- contentPane.add(label);
- textField = new JTextField();
- textField.setBounds(140, 8, 284, 20);
- contentPane.add(textField);
- textField.setColumns(10);
- JTextArea textArea = new JTextArea();
- JButton buttonNoviy = new JButton("\u0421\u043E\u0437\u0434\u0430\u0442\u044C \u043D\u043E\u0432\u044B\u0439");
- buttonNoviy.setForeground(SystemColor.inactiveCaptionText);
- buttonNoviy.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String str=textField.getText().trim();
- if(str.isEmpty())
- {
- JOptionPane.showMessageDialog(null,
- "Введите путь к файлу","Ошибка",0);
- }
- else
- {
- File nf = new File(str+".txt");
- try
- {
- nf.createNewFile();
- JOptionPane.showMessageDialog(null,
- "Файл создан!","Сообщение",1);
- }
- catch(IOException exp)
- {
- JOptionPane.showMessageDialog(null,
- "Файл не создан!","Ошибка",0);
- }
- }
- }
- });
- buttonNoviy.setBackground(Color.LIGHT_GRAY);
- buttonNoviy.setBounds(10, 36, 111, 23);
- contentPane.add(buttonNoviy);
- JButton buttonUdalit = new JButton("\u0423\u0434\u0430\u043B\u0438\u0442\u044C");
- buttonUdalit.setForeground(SystemColor.inactiveCaptionText);
- buttonUdalit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String str=textField.getText().trim();
- if(str.isEmpty())
- {
- JOptionPane.showMessageDialog(null,
- "Введите путь к файлу","Ошибка",0);
- }
- else
- {
- File nf = new File(str);
- if (nf.exists())
- {
- nf.delete();
- JOptionPane.showMessageDialog(null,
- "Файл удален!","Сообщение",1);
- }
- else
- {
- JOptionPane.showMessageDialog(null,
- "Файл не найден!","Ошибка",0);
- }
- }
- }
- });
- buttonUdalit.setBackground(Color.LIGHT_GRAY);
- buttonUdalit.setBounds(10, 66, 111, 23);
- contentPane.add(buttonUdalit);
- JButton buttonPereim = new JButton("\u041F\u0435\u0440\u0435\u0438\u043C\u0435\u043D\u043E\u0432\u0430\u0442\u044C");
- buttonPereim.setForeground(SystemColor.inactiveCaptionText);
- buttonPereim.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String str=textField.getText().trim();
- if(str.isEmpty())
- {
- JOptionPane.showMessageDialog(null,
- "Введите путь к файлу","Ошибка",0);
- }
- else
- {
- File nf = new File(str+".txt");
- if (nf.exists())
- {
- String newName =
- JOptionPane.showInputDialog("Введите новое имя:");
- if (newName==null)newName="";
- if(!newName.trim().isEmpty())
- {
- File newFile =
- new File(nf.getParent()+"\\"+newName);
- nf.renameTo(newFile);
- JOptionPane.showMessageDialog(null,
- "Файл переименован!","Сообщение",1);
- }
- }
- else
- {
- JOptionPane.showMessageDialog(null,
- "Файл не найден!","Ошибка",0);
- }
- }
- }});
- buttonPereim.setBackground(Color.LIGHT_GRAY);
- buttonPereim.setBounds(10, 99, 111, 23);
- contentPane.add(buttonPereim);
- JButton buttonproch = new JButton("\u041F\u0440\u043E\u0447\u0438\u0442\u0430\u0442\u044C");
- buttonproch.setForeground(SystemColor.inactiveCaptionText);
- buttonproch.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- String str = textField.getText().trim();
- if (str.isEmpty())
- {
- JOptionPane.showMessageDialog(null, "Введите путь к файлу!","Ошибка",0);
- }
- else
- {
- File nf = new File(str);
- if (nf.exists())
- {
- try
- {
- FileInputStream obj = new FileInputStream(str);
- BufferedReader in =
- new BufferedReader(new InputStreamReader(obj));
- String tmp = "";
- while(in.ready())
- {
- tmp += (in.readLine()+"\n");
- }
- textArea.setText(tmp);
- in.close();
- obj.close();
- }
- catch(IOException exp) {}
- }
- else
- {
- JOptionPane.showMessageDialog(null, "Файл не найден!","Ошибка",0);
- }
- }
- }});
- buttonproch.setBackground(Color.LIGHT_GRAY);
- buttonproch.setBounds(10, 133, 111, 23);
- contentPane.add(buttonproch);
- JButton buttonZap = new JButton("\u0417\u0430\u043F\u0438\u0441\u0430\u0442\u044C");
- buttonZap.setForeground(SystemColor.inactiveCaptionText);
- buttonZap.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- String str = textField.getText().trim();
- if(str.isEmpty())
- {
- JOptionPane.showMessageDialog(null, "Введите путь к файлу!","Ошибка",0);
- }
- else
- {
- File nf = new File(str);
- if (nf.exists())
- {
- try
- {
- FileOutputStream obj = new FileOutputStream(str);
- BufferedWriter out = new BufferedWriter(new OutputStreamWriter(obj));
- out.write(textArea.getText());
- out.close();
- obj.close();
- JOptionPane.showMessageDialog(null, "Запись выполнена!","Сообщение",1);
- }
- catch (IOException exp) {}
- }
- else
- {
- JOptionPane.showMessageDialog(null, "Файл не найден!","Ошибка",0);
- }
- }
- if(str.isEmpty())
- {
- JOptionPane.showMessageDialog(null, "Введите путь к файлу!","Ошибка",0);
- }
- else
- {
- File nf = new File(str);
- if (nf.exists())
- {
- try
- {
- FileOutputStream obj = new FileOutputStream(str);
- BufferedWriter out = new BufferedWriter(new OutputStreamWriter(obj));
- out.write(textArea.getText());
- out.close();
- obj.close();
- JOptionPane.showMessageDialog(null, "Запись выполнена!","Сообщение",1);
- }
- catch (IOException exp) {}
- }
- else
- {
- JOptionPane.showMessageDialog(null, "Файл не найден!","Ошибка",0);
- }
- }
- }
- });
- buttonZap.setBackground(Color.LIGHT_GRAY);
- buttonZap.setBounds(10, 167, 111, 23);
- contentPane.add(buttonZap);
- JScrollPane scrollPane = new JScrollPane();
- scrollPane.setBounds(140, 40, 284, 211);
- contentPane.add(scrollPane);
- scrollPane.setViewportView(textArea);
- JLabel label_1 = new JLabel("\u0421\u0434\u0435\u043B\u0430\u043D\u043E \u0410\u043B\u0435\u043A\u0441\u0435\u0435\u043C \u0418\u0432\u043B\u0435\u0432\u044B\u043C");
- label_1.setBounds(285, 313, 149, 14);
- contentPane.add(label_1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement