Advertisement
makispaiktis

MainFrame (Swing)

Feb 19th, 2019 (edited)
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4.  
  5. import javax.swing.JButton;
  6. import javax.swing.JFrame;
  7. import javax.swing.JTextArea;
  8.  
  9. public class MainFrame extends JFrame{
  10.    
  11.     // Variables-components
  12.     private TextPanel textPanel;
  13.     //private JButton btn;
  14.     private Toolbar toolbar;
  15.     private FormPanel formPanel;
  16.    
  17.     // Constructor
  18.     public MainFrame() {
  19.         super("Hello World!");                              // Create a JFrame named "Hello World!"
  20.        
  21.         // 1. Layout Manager
  22.         setLayout(new BorderLayout());                      // Orizw me ti eidous Layout tha doulepsw
  23.         textPanel = new TextPanel();                        // Initialize textArea
  24.         //btn = new JButton("Click Me!");                       // Initialize btn
  25.         toolbar = new Toolbar();
  26.         formPanel = new FormPanel();
  27.        
  28.         // 2. Add the components
  29.         add(textPanel, BorderLayout.CENTER);                    // Add the components
  30.         //add(btn, BorderLayout.SOUTH);                     // 2nd argument = position
  31.         add(toolbar, BorderLayout.NORTH);
  32.         add(formPanel, BorderLayout.WEST);
  33.        
  34.         toolbar.setStringListener(new StringListener() {
  35.             public void textEmitted(String text) {
  36.                 System.out.println(text);
  37.                 textPanel.appendText(text);
  38.             }
  39.         });
  40.        
  41.        
  42.         // 3. When I click on btn, I want the message "Hello" to be written in textArea
  43.         /*
  44.         btn.addActionListener(new ActionListener() {        // Add the unimplemented function of this class
  45.  
  46.             //@Override
  47.             public void actionPerformed(ActionEvent arg0) {
  48.                 textPanel.appendText("Hello\n");
  49.                
  50.             }
  51.            
  52.         });
  53.         */ 
  54.        
  55.         // 4. Basic operations
  56.         setSize(600, 600);                                  // Set dimensions to my window
  57.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     // Gia na kleinei to parathyro otan pataw to "X"   
  58.         setVisible(true);                                   // To make my window visible (it is invisible by default)
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement