Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package textedit;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import javax.swing.JTextField;
- import javax.swing.JButton;
- import java.awt.GridBagLayout;
- import java.awt.GridBagConstraints;
- import java.awt.Insets;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import java.awt.event.ActionListener;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.awt.event.ActionEvent;
- public class EditorFrame extends JFrame {
- private JPanel contentPane;
- private JTextField textField;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- EditorFrame frame = new EditorFrame();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public EditorFrame() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- contentPane.setLayout(new BorderLayout(0, 0));
- setContentPane(contentPane);
- JPanel panel = new JPanel();
- contentPane.add(panel, BorderLayout.NORTH);
- JLabel label = new JLabel("\u041F\u0443\u0442\u044C \u043A \u0444\u0430\u0439\u043B\u0443:");
- panel.add(label);
- textField = new JTextField();
- panel.add(textField);
- textField.setColumns(30);
- JTextArea textArea = new JTextArea();
- JPanel panel_1 = new JPanel();
- contentPane.add(panel_1, BorderLayout.WEST);
- GridBagLayout gbl_panel_1 = new GridBagLayout();
- gbl_panel_1.columnWidths = new int[] {85};
- gbl_panel_1.rowHeights = new int[] {23, 0, 0, 0, 0};
- gbl_panel_1.columnWeights = new double[]{1.0};
- gbl_panel_1.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
- panel_1.setLayout(gbl_panel_1);
- JButton button = new JButton("\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try {
- PrintWriter writer = new PrintWriter(textField.getText().trim());
- writer.print(textArea.getText());
- writer.flush();
- writer.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- });
- GridBagConstraints gbc_button = new GridBagConstraints();
- gbc_button.anchor = GridBagConstraints.NORTHWEST;
- gbc_button.insets = new Insets(0, 0, 5, 0);
- gbc_button.gridx = 0;
- gbc_button.gridy = 0;
- panel_1.add(button, gbc_button);
- JButton button_1 = new JButton("\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C");
- button_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- });
- GridBagConstraints gbc_button_1 = new GridBagConstraints();
- gbc_button_1.insets = new Insets(0, 0, 5, 0);
- gbc_button_1.anchor = GridBagConstraints.NORTHWEST;
- gbc_button_1.gridx = 0;
- gbc_button_1.gridy = 1;
- panel_1.add(button_1, gbc_button_1);
- JButton button_2 = new JButton("\u0423\u0434\u0430\u043B\u0438\u0442\u044C");
- button_2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- File f = new File(textField.getText().trim());
- f.delete();
- }
- });
- GridBagConstraints gbc_button_2 = new GridBagConstraints();
- gbc_button_2.anchor = GridBagConstraints.NORTHWEST;
- gbc_button_2.insets = new Insets(0, 0, 5, 0);
- gbc_button_2.gridx = 0;
- gbc_button_2.gridy = 2;
- panel_1.add(button_2, gbc_button_2);
- JButton button_3 = new JButton("\u0421\u043E\u0437\u0434\u0430\u0442\u044C");
- button_3.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- File f = new File(textField.getText().trim());
- try {
- f.createNewFile();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
- });
- GridBagConstraints gbc_button_3 = new GridBagConstraints();
- gbc_button_3.anchor = GridBagConstraints.NORTHWEST;
- gbc_button_3.gridx = 0;
- gbc_button_3.gridy = 3;
- panel_1.add(button_3, gbc_button_3);
- JScrollPane scrollPane = new JScrollPane();
- contentPane.add(scrollPane, BorderLayout.CENTER);
- scrollPane.setViewportView(textArea);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement