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 javax.swing.JTextArea;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JLabel;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Scanner;
- public class Test1 extends JFrame {
- private JPanel contentPane;
- private static File f = new File("ourbasefile.kln");
- private static Test1 frame = null;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- frame = new Test1();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- /**
- *
- */
- public Test1() {
- setTitle("No name, sry");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 600, 450);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JTextArea textArea = new JTextArea();
- textArea.setBounds(10, 23, 553, 92);
- contentPane.add(textArea);
- JButton btnWriteToFile = new JButton("Write to file");
- btnWriteToFile.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- try {
- FileWriter fw = new FileWriter(f);
- fw.write(textArea.getText());
- fw.close();
- } catch (IOException ex) {
- // TODO Auto-generated catch block
- ex.printStackTrace();
- }
- }
- });
- btnWriteToFile.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- });
- btnWriteToFile.setBounds(274, 287, 89, 23);
- contentPane.add(btnWriteToFile);
- JLabel lblNewLabel = new JLabel("");
- lblNewLabel.setBounds(10, 171, 553, 92);
- contentPane.add(lblNewLabel);
- JButton btnReadFromFile = new JButton("Read from file");
- btnReadFromFile.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- try {
- Scanner s = new Scanner(f);
- String str = s.next();
- s.close();
- lblNewLabel.setText(str);
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- });
- btnReadFromFile.setBounds(373, 287, 89, 23);
- contentPane.add(btnReadFromFile);
- JButton btnExitProgram = new JButton("Cancel(r)");
- btnExitProgram.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- Test1.frame.dispose();
- }
- });
- btnExitProgram.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- }
- });
- btnExitProgram.setBounds(472, 287, 89, 23);
- contentPane.add(btnExitProgram);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement