Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package app13;
- import java.awt.BorderLayout;
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- public class Okno extends JFrame implements ActionListener{
- DrawPanel p;
- // конструктор класса
- public Okno() {
- setTitle("MAGIC SQUARE");
- setBounds(0, 0, 800, 600);
- getContentPane().add(createPanel());
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setVisible(true);
- }
- //
- public JButton createButton(String title){
- JButton b = new JButton(title);
- b.addActionListener(this);
- return b;
- }
- //
- public JPanel createPanel() {
- /*
- // создает объект типа DrawPanel
- DrawPanel p = new DrawPanel();
- //
- return p;
- */
- // главная панель
- JPanel mainPanel = new JPanel();
- mainPanel.setLayout(new BorderLayout());
- // панель управления
- JPanel controlPanel = new JPanel();
- controlPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 20, 10));
- controlPanel.add(createButton("START"));
- controlPanel.add(createButton("STOP"));
- // панель для графики
- p = new DrawPanel();
- // добавляем на север
- mainPanel.add(controlPanel, BorderLayout.SOUTH);
- // добавляем на центр
- mainPanel.add(p, BorderLayout.CENTER);
- return mainPanel;
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- //
- if(e.getActionCommand().equals("START")){
- System.out.println("START!");
- p.startAnimation();
- }else if(e.getActionCommand().equals("STOP")){
- System.out.println("STOP!");
- p.stopAnimation();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement