Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.example;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class Panel extends JPanel {
- private static final Dimension WINDOW_SIZE = new Dimension(800, 600);
- private static final Color WINDOW_BACKGROUND_COLOR = new Color(0, 0, 64);
- private static final String WINDOW_NAME = "WINDOW_NAME";
- private static final int TIMER_DELAY = 10;
- public static void main(String[] args) {
- new Panel();
- }
- public Panel() {
- setupFrameAndPanel();
- new Timer(TIMER_DELAY, new TimerListener()).start();
- }
- private class TimerListener implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent e) {
- //
- }
- }
- private class KeyListener extends KeyAdapter {
- @Override
- public void keyPressed(KeyEvent e) {
- int keyCode = e.getKeyCode();
- //
- }
- @Override
- public void keyReleased(KeyEvent e) {
- int keyCode = e.getKeyCode();
- //
- }
- }
- private class MouseListener extends MouseAdapter {
- //
- }
- @Override
- protected void paintComponent(Graphics g) {
- super.paintComponent(g);
- //
- }
- private void setupFrameAndPanel() {
- var frame = new JFrame(WINDOW_NAME);
- frame.setSize(WINDOW_SIZE);
- setFocusTraversalKeysEnabled(true);
- setFocusable(true);
- addKeyListener(new KeyListener());
- addMouseListener(new MouseListener());
- frame.add(this);
- setBackground(WINDOW_BACKGROUND_COLOR);
- frame.setResizable(true);
- frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement