Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.Serializable;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JTextField;
- public class SecondFrame extends JFrame implements ActionListener {
- private JTextField jtfSecond1 = null;
- private JButton jbSecond1 = null;
- private StringBuffer sb = null;
- private String result = null;
- private FirstFrame jframeFirst = null;
- public SecondFrame() throws ClassNotFoundException, IOException {
- setTitle("Второе окно");
- setBounds(800, 100, 600, 200);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setVisible(true);
- GridLayout gl = new GridLayout(2, 1);
- setLayout(gl);
- jtfSecond1 = new JTextField();
- jbSecond1 = new JButton();
- jbSecond1.setText("Отправить текст");
- add(jtfSecond1);
- add(jbSecond1);
- jbSecond1.addActionListener(this);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- ffM();
- stM(jtfSecond1, jframeFirst.jtfFirst1);
- } catch (ClassNotFoundException | IOException e2) {
- e2.printStackTrace();
- }
- }
- private void ffM() throws IOException, ClassNotFoundException {
- FileInputStream fis = new FileInputStream("text.ser");
- ObjectInputStream oin = new ObjectInputStream(fis);
- jframeFirst = (FirstFrame) oin.readObject();
- oin.close();
- }
- private void stM(JTextField jtfm1, JTextField jtfm2) throws IOException {
- sb = new StringBuffer();
- result = new String();
- for (int i = 0; i < 10; i++) {
- result = sb.append("i#" + i + "=" + jtfm1.getText() + "; ")
- .toString();
- jtfm2.setText(result);
- }
- FileOutputStream fos = new FileOutputStream("text.ser");
- ObjectOutputStream oos = new ObjectOutputStream(fos);
- oos.writeObject(jframeFirst);
- oos.flush();
- oos.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment