Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JTextArea;
- public class MainFrame extends JFrame{
- // Variables-components
- private TextPanel textPanel;
- //private JButton btn;
- private Toolbar toolbar;
- private FormPanel formPanel;
- // Constructor
- public MainFrame() {
- super("Hello World!"); // Create a JFrame named "Hello World!"
- // 1. Layout Manager
- setLayout(new BorderLayout()); // Orizw me ti eidous Layout tha doulepsw
- textPanel = new TextPanel(); // Initialize textArea
- //btn = new JButton("Click Me!"); // Initialize btn
- toolbar = new Toolbar();
- formPanel = new FormPanel();
- // 2. Add the components
- add(textPanel, BorderLayout.CENTER); // Add the components
- //add(btn, BorderLayout.SOUTH); // 2nd argument = position
- add(toolbar, BorderLayout.NORTH);
- add(formPanel, BorderLayout.WEST);
- toolbar.setStringListener(new StringListener() {
- public void textEmitted(String text) {
- System.out.println(text);
- textPanel.appendText(text);
- }
- });
- // 3. When I click on btn, I want the message "Hello" to be written in textArea
- /*
- btn.addActionListener(new ActionListener() { // Add the unimplemented function of this class
- //@Override
- public void actionPerformed(ActionEvent arg0) {
- textPanel.appendText("Hello\n");
- }
- });
- */
- // 4. Basic operations
- setSize(600, 600); // Set dimensions to my window
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Gia na kleinei to parathyro otan pataw to "X"
- setVisible(true); // To make my window visible (it is invisible by default)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement