Advertisement
Guest User

FORUM PROGRAMMISTOV

a guest
Apr 18th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.77 KB | None | 0 0
  1.  
  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.  
  10. import org.omg.CORBA.portable.OutputStream;
  11. import org.omg.CORBA_2_3.portable.InputStream;
  12.  
  13. import javax.swing.JLabel;
  14. import javax.swing.JOptionPane;
  15.  
  16. import java.awt.Color;
  17. import javax.swing.JTextField;
  18. import javax.swing.JButton;
  19. import java.awt.event.ActionListener;
  20. import java.io.BufferedReader;
  21. import java.io.BufferedWriter;
  22. import java.io.File;
  23. import java.io.FileInputStream;
  24. import java.io.FileOutputStream;
  25. import java.io.IOException;
  26. import java.io.InputStreamReader;
  27. import java.io.OutputStreamWriter;
  28. import java.awt.event.ActionEvent;
  29. import java.awt.Toolkit;
  30. import javax.swing.JScrollPane;
  31. import javax.swing.JTextArea;
  32. import java.awt.Font;
  33. import java.awt.TextArea;
  34. import javax.swing.JEditorPane;
  35. import javax.swing.JFileChooser;
  36. import java.awt.SystemColor;
  37.  
  38. public class Bloknot_v2 extends JFrame {
  39.  
  40. //protected static final String = null;
  41. private JPanel contentPane;
  42. private JTextField textField;
  43.  
  44. /**
  45. * Launch the application.
  46. */
  47. public static void main(String[] args) {
  48. EventQueue.invokeLater(new Runnable() {
  49. public void run() {
  50. try {
  51. Bloknot_v2 frame = new Bloknot_v2();
  52. frame.setVisible(true);
  53. } catch (Exception e) {
  54. e.printStackTrace();
  55. }
  56. }
  57. });
  58. }
  59.  
  60. /**
  61. * Create the frame.
  62. */
  63. public Bloknot_v2() {
  64. setFont(new Font("Dialog", Font.PLAIN, 9));
  65. 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");
  66. setIconImage(Toolkit.getDefaultToolkit().getImage(Bloknot_v2.class.getResource("/javax/swing/plaf/metal/icons/Inform.gif")));
  67. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  68. setBounds(100, 100, 450, 298);
  69. contentPane = new JPanel();
  70. contentPane.setBackground(Color.GRAY);
  71. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  72. setContentPane(contentPane);
  73. contentPane.setLayout(null);
  74.  
  75. JButton btnBrowse = new JButton("Browse...");
  76. btnBrowse.setForeground(SystemColor.controlText);
  77. btnBrowse.setBackground(Color.LIGHT_GRAY);
  78. btnBrowse.addActionListener(new ActionListener() {
  79. public void actionPerformed(ActionEvent arg0) {
  80.  
  81. JFileChooser fc = new JFileChooser();
  82. if( fc.showDialog(fc, "Стартуем!Я сказала Стартуем!") == JFileChooser.APPROVE_OPTION) {
  83. @SuppressWarnings("unused")
  84.  
  85. String f = fc.getSelectedFile().getAbsolutePath();
  86. File nf = new File(f+".txt");
  87.  
  88. }
  89. }
  90.  
  91.  
  92.  
  93.  
  94. });
  95. btnBrowse.setBounds(10, 201, 111, 23);
  96. contentPane.add(btnBrowse);
  97.  
  98. JLabel label = new JLabel("\u0423\u043A\u0430\u0436\u0438\u0442\u0435 \u043F\u0443\u0442\u044C \u043A \u0444\u0430\u0439\u043B\u0443:");
  99. label.setBounds(10, 11, 355, 14);
  100. contentPane.add(label);
  101.  
  102. textField = new JTextField();
  103. textField.setBounds(140, 8, 284, 20);
  104. contentPane.add(textField);
  105. textField.setColumns(10);
  106.  
  107. JTextArea textArea = new JTextArea();
  108.  
  109.  
  110. JButton buttonNoviy = new JButton("\u0421\u043E\u0437\u0434\u0430\u0442\u044C \u043D\u043E\u0432\u044B\u0439");
  111. buttonNoviy.setForeground(SystemColor.inactiveCaptionText);
  112. buttonNoviy.addActionListener(new ActionListener() {
  113. public void actionPerformed(ActionEvent e) {
  114. String str=textField.getText().trim();
  115. if(str.isEmpty())
  116. {
  117. JOptionPane.showMessageDialog(null,
  118. "Введите путь к файлу","Ошибка",0);
  119.  
  120. }
  121. else
  122. {
  123. File nf = new File(str+".txt");
  124. try
  125. {
  126. nf.createNewFile();
  127. JOptionPane.showMessageDialog(null,
  128. "Файл создан!","Сообщение",1);
  129. }
  130. catch(IOException exp)
  131. {
  132. JOptionPane.showMessageDialog(null,
  133. "Файл не создан!","Ошибка",0);
  134. }
  135. }
  136. }
  137. });
  138. buttonNoviy.setBackground(Color.LIGHT_GRAY);
  139. buttonNoviy.setBounds(10, 36, 111, 23);
  140. contentPane.add(buttonNoviy);
  141.  
  142.  
  143.  
  144. JButton buttonUdalit = new JButton("\u0423\u0434\u0430\u043B\u0438\u0442\u044C");
  145. buttonUdalit.setForeground(SystemColor.inactiveCaptionText);
  146. buttonUdalit.addActionListener(new ActionListener() {
  147. public void actionPerformed(ActionEvent e) {
  148. String str=textField.getText().trim();
  149. if(str.isEmpty())
  150. {
  151. JOptionPane.showMessageDialog(null,
  152. "Введите путь к файлу","Ошибка",0);
  153.  
  154. }
  155. else
  156. {
  157. File nf = new File(str);
  158. if (nf.exists())
  159. {
  160. nf.delete();
  161. JOptionPane.showMessageDialog(null,
  162. "Файл удален!","Сообщение",1);
  163. }
  164. else
  165. {
  166. JOptionPane.showMessageDialog(null,
  167. "Файл не найден!","Ошибка",0);
  168. }
  169.  
  170. }
  171. }
  172. });
  173. buttonUdalit.setBackground(Color.LIGHT_GRAY);
  174. buttonUdalit.setBounds(10, 66, 111, 23);
  175. contentPane.add(buttonUdalit);
  176.  
  177. JButton buttonPereim = new JButton("\u041F\u0435\u0440\u0435\u0438\u043C\u0435\u043D\u043E\u0432\u0430\u0442\u044C");
  178. buttonPereim.setForeground(SystemColor.inactiveCaptionText);
  179. buttonPereim.addActionListener(new ActionListener() {
  180. public void actionPerformed(ActionEvent e) {
  181. String str=textField.getText().trim();
  182. if(str.isEmpty())
  183. {
  184. JOptionPane.showMessageDialog(null,
  185. "Введите путь к файлу","Ошибка",0);
  186.  
  187. }
  188. else
  189. {
  190. File nf = new File(str+".txt");
  191. if (nf.exists())
  192. {
  193. String newName =
  194. JOptionPane.showInputDialog("Введите новое имя:");
  195. if (newName==null)newName="";
  196. if(!newName.trim().isEmpty())
  197. {
  198. File newFile =
  199. new File(nf.getParent()+"\\"+newName);
  200. nf.renameTo(newFile);
  201. JOptionPane.showMessageDialog(null,
  202. "Файл переименован!","Сообщение",1);
  203.  
  204. }
  205. }
  206. else
  207. {
  208. JOptionPane.showMessageDialog(null,
  209. "Файл не найден!","Ошибка",0);
  210. }
  211. }
  212. }});
  213. buttonPereim.setBackground(Color.LIGHT_GRAY);
  214. buttonPereim.setBounds(10, 99, 111, 23);
  215. contentPane.add(buttonPereim);
  216.  
  217. JButton buttonproch = new JButton("\u041F\u0440\u043E\u0447\u0438\u0442\u0430\u0442\u044C");
  218. buttonproch.setForeground(SystemColor.inactiveCaptionText);
  219. buttonproch.addActionListener(new ActionListener() {
  220. public void actionPerformed(ActionEvent arg0) {
  221. String str = textField.getText().trim();
  222. if (str.isEmpty())
  223. {
  224. JOptionPane.showMessageDialog(null, "Введите путь к файлу!","Ошибка",0);
  225. }
  226. else
  227. {
  228. File nf = new File(str);
  229. if (nf.exists())
  230. {
  231. try
  232. {
  233. FileInputStream obj = new FileInputStream(str);
  234. BufferedReader in =
  235. new BufferedReader(new InputStreamReader(obj));
  236. String tmp = "";
  237. while(in.ready())
  238. {
  239. tmp += (in.readLine()+"\n");
  240. }
  241. textArea.setText(tmp);
  242. in.close();
  243. obj.close();
  244. }
  245. catch(IOException exp) {}
  246. }
  247. else
  248. {
  249. JOptionPane.showMessageDialog(null, "Файл не найден!","Ошибка",0);
  250. }
  251. }
  252. }});
  253. buttonproch.setBackground(Color.LIGHT_GRAY);
  254. buttonproch.setBounds(10, 133, 111, 23);
  255. contentPane.add(buttonproch);
  256.  
  257. JButton buttonZap = new JButton("\u0417\u0430\u043F\u0438\u0441\u0430\u0442\u044C");
  258. buttonZap.setForeground(SystemColor.inactiveCaptionText);
  259. buttonZap.addActionListener(new ActionListener() {
  260. public void actionPerformed(ActionEvent arg0) {
  261. String str = textField.getText().trim();
  262. if(str.isEmpty())
  263. {
  264. JOptionPane.showMessageDialog(null, "Введите путь к файлу!","Ошибка",0);
  265. }
  266. else
  267. {
  268. File nf = new File(str);
  269. if (nf.exists())
  270. {
  271. try
  272. {
  273. FileOutputStream obj = new FileOutputStream(str);
  274. BufferedWriter out = new BufferedWriter(new OutputStreamWriter(obj));
  275. out.write(textArea.getText());
  276. out.close();
  277. obj.close();
  278. JOptionPane.showMessageDialog(null, "Запись выполнена!","Сообщение",1);
  279. }
  280. catch (IOException exp) {}
  281. }
  282. else
  283. {
  284. JOptionPane.showMessageDialog(null, "Файл не найден!","Ошибка",0);
  285. }
  286. }
  287. if(str.isEmpty())
  288. {
  289. JOptionPane.showMessageDialog(null, "Введите путь к файлу!","Ошибка",0);
  290. }
  291. else
  292. {
  293. File nf = new File(str);
  294. if (nf.exists())
  295. {
  296. try
  297. {
  298. FileOutputStream obj = new FileOutputStream(str);
  299. BufferedWriter out = new BufferedWriter(new OutputStreamWriter(obj));
  300. out.write(textArea.getText());
  301. out.close();
  302. obj.close();
  303. JOptionPane.showMessageDialog(null, "Запись выполнена!","Сообщение",1);
  304. }
  305. catch (IOException exp) {}
  306. }
  307. else
  308. {
  309. JOptionPane.showMessageDialog(null, "Файл не найден!","Ошибка",0);
  310. }
  311. }
  312. }
  313. });
  314. buttonZap.setBackground(Color.LIGHT_GRAY);
  315. buttonZap.setBounds(10, 167, 111, 23);
  316. contentPane.add(buttonZap);
  317.  
  318.  
  319.  
  320. JScrollPane scrollPane = new JScrollPane();
  321. scrollPane.setBounds(140, 40, 284, 211);
  322. contentPane.add(scrollPane);
  323. scrollPane.setViewportView(textArea);
  324.  
  325. 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");
  326. label_1.setBounds(285, 313, 149, 14);
  327. contentPane.add(label_1);
  328.  
  329. }
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement