Advertisement
sergAccount

Untitled

Dec 20th, 2020
688
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.20 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 app13;
  7.  
  8. import java.awt.BorderLayout;
  9. import java.awt.FlowLayout;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. import javax.swing.JButton;
  13. import javax.swing.JFrame;
  14. import javax.swing.JPanel;
  15.  
  16. public class Okno extends JFrame implements ActionListener{
  17.    
  18.     DrawPanel p;
  19.     // конструктор класса
  20.     public Okno() {
  21.         setTitle("MAGIC SQUARE");
  22.         setBounds(0, 0, 800, 600);
  23.         getContentPane().add(createPanel());
  24.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  25.         setVisible(true);
  26.     }    
  27.     //
  28.     public JButton createButton(String title){
  29.         JButton b = new JButton(title);
  30.         b.addActionListener(this);
  31.         return b;        
  32.     }
  33.     //      
  34.     public JPanel createPanel() {
  35.         /*
  36.         // создает объект типа DrawPanel
  37.         DrawPanel p = new DrawPanel();
  38.         //
  39.         return p;
  40.         */
  41.         // главная панель
  42.         JPanel mainPanel = new JPanel();
  43.         mainPanel.setLayout(new BorderLayout());
  44.         // панель управления
  45.         JPanel controlPanel = new JPanel();
  46.         controlPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 20, 10));
  47.         controlPanel.add(createButton("START"));
  48.         controlPanel.add(createButton("STOP"));
  49.         // панель для графики
  50.         p = new DrawPanel();
  51.         // добавляем на север
  52.         mainPanel.add(controlPanel, BorderLayout.SOUTH);
  53.         // добавляем на центр
  54.         mainPanel.add(p, BorderLayout.CENTER);
  55.        
  56.         return mainPanel;
  57.     }
  58.     @Override
  59.     public void actionPerformed(ActionEvent e) {
  60.         //        
  61.         if(e.getActionCommand().equals("START")){
  62.             System.out.println("START!");
  63.             p.startAnimation();
  64.         }else if(e.getActionCommand().equals("STOP")){
  65.             System.out.println("STOP!");
  66.             p.stopAnimation();
  67.         }
  68.     }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement