Advertisement
sergAccount

Untitled

Sep 18th, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package app2;
  7.  
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import javax.swing.*;
  11.  
  12. /**
  13.  *
  14.  * @author Student1
  15.  */
  16. public class App2 {    
  17.     //
  18.     public static JPanel createPanel(){
  19.         //
  20.         AppActionListener listener = new AppActionListener();        
  21.         JPanel p = new JPanel();        
  22.         JButton button1 = new JButton("Кнопка1");
  23.         button1.setActionCommand("BUTTON1_COMMAND");        
  24.         button1.addActionListener(listener);      
  25.         p.add(button1);
  26.        
  27.         JButton button2 = new JButton("Кнопка2");
  28.         button2.setActionCommand("BUTTON2_COMMAND");
  29.         button2.addActionListener(listener);
  30.         p.add(button2);
  31.         //
  32.         JLabel label = new JLabel("Текст:");
  33.         p.add(label);
  34.        
  35.         JTextArea tx = new JTextArea(5, 20);              
  36.         p.add(tx);
  37.         return p;
  38.     }    
  39.     /**
  40.      * @param args the command line arguments
  41.      */
  42.     public static void main(String[] args) {
  43.         // TODO code application logic here        
  44.         JFrame frame = new JFrame("HelloWorldApp");
  45.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  46.         frame.getContentPane().add(createPanel());
  47.         frame.setBounds(0, 0, 800, 600);
  48.         frame.setVisible(true);                
  49.     }    
  50. }
  51.  
  52.  
  53.   /*
  54.         button1.addActionListener(new ActionListener(){
  55.             @Override
  56.             public void actionPerformed(ActionEvent ae) {
  57.                 //
  58.                 Object obj = ae.getSource();
  59.                 System.out.println("source.class=" + obj.getClass());
  60.                 String actionCommand = ae.getActionCommand();
  61.                 //
  62.                 System.out.println("actionCommand=" + actionCommand);
  63.                 System.out.println("Событие!!!");
  64.             }
  65.         });*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement