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.
- */
- import javax.swing.*;
- import java.awt.event.*;
- /**
- *
- * @author Sergey
- */
- public class Okno extends JFrame{
- private Pole gameP;
- private int slogn;
- public Okno(int slogn){
- //
- this.slogn = slogn;
- addKeyListener(new MyKey());
- setFocusable(true);
- setResizable(false);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //
- setBounds(0, 0, 800, 600);
- setTitle("Игра: Новогодний дождь");
- //
- gameP = new Pole(slogn);
- getContentPane().add(gameP);
- //
- setVisible(true);
- }
- private class MyKey implements KeyListener{
- //
- @Override
- public void keyPressed(KeyEvent e){
- //
- int key = e.getKeyCode(); //System.out.println("key=" + key);
- if(key==27){
- System.exit(0);
- }else if(key==37){
- //
- if(gameP.x - 30 > -48){
- gameP.x -= 30;
- }else{
- gameP.x = 752;
- }
- }else if(key==39){
- //
- if(gameP.x + 30 < 752){
- gameP.x += 30;
- }else{
- gameP.x = -48;
- }
- }
- }
- @Override
- public void keyTyped(KeyEvent e){}
- @Override
- public void keyReleased(KeyEvent e){}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement