Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. package textedit;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.EventQueue;
  5.  
  6. import javax.swing.JFrame;
  7. import javax.swing.JPanel;
  8. import javax.swing.border.EmptyBorder;
  9. import javax.swing.JLabel;
  10. import javax.swing.JTextField;
  11. import javax.swing.JButton;
  12. import java.awt.GridBagLayout;
  13. import java.awt.GridBagConstraints;
  14. import java.awt.Insets;
  15. import javax.swing.JScrollPane;
  16. import javax.swing.JTextArea;
  17. import java.awt.event.ActionListener;
  18. import java.io.File;
  19. import java.io.FileNotFoundException;
  20. import java.io.IOException;
  21. import java.io.PrintWriter;
  22. import java.awt.event.ActionEvent;
  23.  
  24. public class EditorFrame extends JFrame {
  25.  
  26. private JPanel contentPane;
  27. private JTextField textField;
  28.  
  29. /**
  30. * Launch the application.
  31. */
  32. public static void main(String[] args) {
  33. EventQueue.invokeLater(new Runnable() {
  34. public void run() {
  35. try {
  36. EditorFrame frame = new EditorFrame();
  37. frame.setVisible(true);
  38. } catch (Exception e) {
  39. e.printStackTrace();
  40. }
  41. }
  42. });
  43. }
  44.  
  45. /**
  46. * Create the frame.
  47. */
  48. public EditorFrame() {
  49. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  50. setBounds(100, 100, 450, 300);
  51. contentPane = new JPanel();
  52. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  53. contentPane.setLayout(new BorderLayout(0, 0));
  54. setContentPane(contentPane);
  55.  
  56. JPanel panel = new JPanel();
  57. contentPane.add(panel, BorderLayout.NORTH);
  58.  
  59. JLabel label = new JLabel("\u041F\u0443\u0442\u044C \u043A \u0444\u0430\u0439\u043B\u0443:");
  60. panel.add(label);
  61.  
  62. textField = new JTextField();
  63. panel.add(textField);
  64. textField.setColumns(30);
  65.  
  66. JTextArea textArea = new JTextArea();
  67.  
  68. JPanel panel_1 = new JPanel();
  69. contentPane.add(panel_1, BorderLayout.WEST);
  70. GridBagLayout gbl_panel_1 = new GridBagLayout();
  71. gbl_panel_1.columnWidths = new int[] {85};
  72. gbl_panel_1.rowHeights = new int[] {23, 0, 0, 0, 0};
  73. gbl_panel_1.columnWeights = new double[]{1.0};
  74. gbl_panel_1.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  75. panel_1.setLayout(gbl_panel_1);
  76.  
  77. JButton button = new JButton("\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C");
  78. button.addActionListener(new ActionListener() {
  79. public void actionPerformed(ActionEvent arg0) {
  80. try {
  81. PrintWriter writer = new PrintWriter(textField.getText().trim());
  82. writer.print(textArea.getText());
  83. writer.flush();
  84. writer.close();
  85. } catch (FileNotFoundException e) {
  86. e.printStackTrace();
  87. }
  88. }
  89. });
  90. GridBagConstraints gbc_button = new GridBagConstraints();
  91. gbc_button.anchor = GridBagConstraints.NORTHWEST;
  92. gbc_button.insets = new Insets(0, 0, 5, 0);
  93. gbc_button.gridx = 0;
  94. gbc_button.gridy = 0;
  95. panel_1.add(button, gbc_button);
  96.  
  97. JButton button_1 = new JButton("\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C");
  98. button_1.addActionListener(new ActionListener() {
  99. public void actionPerformed(ActionEvent e) {
  100. }
  101. });
  102. GridBagConstraints gbc_button_1 = new GridBagConstraints();
  103. gbc_button_1.insets = new Insets(0, 0, 5, 0);
  104. gbc_button_1.anchor = GridBagConstraints.NORTHWEST;
  105. gbc_button_1.gridx = 0;
  106. gbc_button_1.gridy = 1;
  107. panel_1.add(button_1, gbc_button_1);
  108.  
  109. JButton button_2 = new JButton("\u0423\u0434\u0430\u043B\u0438\u0442\u044C");
  110. button_2.addActionListener(new ActionListener() {
  111. public void actionPerformed(ActionEvent e) {
  112. File f = new File(textField.getText().trim());
  113. f.delete();
  114. }
  115. });
  116. GridBagConstraints gbc_button_2 = new GridBagConstraints();
  117. gbc_button_2.anchor = GridBagConstraints.NORTHWEST;
  118. gbc_button_2.insets = new Insets(0, 0, 5, 0);
  119. gbc_button_2.gridx = 0;
  120. gbc_button_2.gridy = 2;
  121. panel_1.add(button_2, gbc_button_2);
  122.  
  123. JButton button_3 = new JButton("\u0421\u043E\u0437\u0434\u0430\u0442\u044C");
  124. button_3.addActionListener(new ActionListener() {
  125. public void actionPerformed(ActionEvent e) {
  126. File f = new File(textField.getText().trim());
  127. try {
  128. f.createNewFile();
  129. } catch (IOException e1) {
  130. e1.printStackTrace();
  131. }
  132. }
  133. });
  134. GridBagConstraints gbc_button_3 = new GridBagConstraints();
  135. gbc_button_3.anchor = GridBagConstraints.NORTHWEST;
  136. gbc_button_3.gridx = 0;
  137. gbc_button_3.gridy = 3;
  138. panel_1.add(button_3, gbc_button_3);
  139.  
  140. JScrollPane scrollPane = new JScrollPane();
  141. contentPane.add(scrollPane, BorderLayout.CENTER);
  142.  
  143.  
  144. scrollPane.setViewportView(textArea);
  145. }
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement