Advertisement
sergAccount

Untitled

Sep 25th, 2016
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 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 static app2.App2.createPanel;
  9. import javax.swing.JButton;
  10. import javax.swing.JFrame;
  11. import javax.swing.JPanel;
  12.  
  13. /**
  14.  *
  15.  * @author Student1
  16.  */
  17. public class Okno extends JFrame {
  18.  
  19.     public Okno() {
  20.         setTitle("Калькулятор");
  21.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  22.         getContentPane().add(createPanel());
  23.         setBounds(0, 0, 800, 600);
  24.         setVisible(true);
  25.     }
  26.    
  27.     public static JButton[] createButtons(){        
  28.         JButton[] array = new JButton[10];          
  29.         //fori + tab
  30.         for(int i = 0; i < array.length; i++){
  31.             String title = "" + i;
  32.             JButton button = new JButton(title);                        
  33.             //button.setActionCommand("");
  34.             array[i] = button;
  35.         }
  36.         //
  37.        
  38.         //
  39.         return array;
  40.     }
  41.     //
  42.     public static JPanel createPanel() {
  43.         //
  44.         AppActionListener listener = new AppActionListener();
  45.         JPanel p = new JPanel();        
  46.         JButton[] buttons = createButtons();
  47.         for(int i = 0; i < buttons.length; i++){
  48.             JButton button = buttons[i];
  49.             button.addActionListener(listener);
  50.             p.add(button);
  51.         }        
  52.         // добавляем кнопку Выход
  53.         JButton exitButton = new JButton("Выход");
  54.         exitButton.setActionCommand(AppCommands.EXIT_COMMAND);
  55.         exitButton.addActionListener(listener);
  56.         p.add(exitButton);
  57.        
  58.         return p;
  59.     }
  60. }
  61.  
  62. //alt+shift+F
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement