Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.text.Document;

public class Main extends JFrame {
    JLabel nameLabel = new JLabel("Name:");
    JLabel mirroredNameLabel = new JLabel("Mirrored:");
    JTextField name = new JTextField(20);
    JTextField mirroredName = new JTextField(20);

    public Main() {
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setLayout(new GridLayout(2, 0));

        Container contentPane = this.getContentPane();
        contentPane.add(nameLabel);
        contentPane.add(name);
        contentPane.add(mirroredNameLabel);
        contentPane.add(mirroredName);

        Document nameModel = name.getDocument();
        mirroredName.setDocument(nameModel);

        pack();
        setVisible(true);
    }

    public static void main(String[] args) {
        Main frame = new Main();

    }
}