forked from shintan777/StackItUp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStac.java
More file actions
94 lines (90 loc) · 1.76 KB
/
Stac.java
File metadata and controls
94 lines (90 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.mini.project;
import java.awt.event.KeyEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyListener;
import java.util.*;
@SuppressWarnings({ "serial", "unused" })
class Stac extends JFrame{
Block blk = new Block();
Stac()
{ super("StackItUp!!!");
addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
//blk.keyReleased(e);
}
@Override
public void keyPressed(KeyEvent e) {
blk.keyPressed(e);
}
});
setFocusable(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(30,30,720,720);
//setSize(720,720);
setBackground(Color.darkGray);
setResizable(false);
setVisible(true);
}
public void move() {
blk.moverect();
}
@Override
public void paint(Graphics g) {
super.paint(g);
blk.paint(g);
}
public static void main(String[]args)throws InterruptedException {
{
Stac rect=new Stac();
while(true)
{
rect.move();
rect.repaint();
Thread.sleep(15);
}
}
}
}
class Block extends JFrame{
int x=0,y=600,w=250,h=50,cntr=1;
double vel=2.0;
public void moverect()
{
if(x+vel<720 && x+vel>0)
{x+=vel;
}
if(x+vel>=720-w)
{vel=vel*(-1);
x+=vel;
}
if(x+vel==0)
{vel=vel*(-1);
x+=vel;
}
}
public void nextrect()
{cntr++;
x=600;
y+=50;
}
public void drop(){
}
@Override
public void paint(Graphics g)
{
g.setColor(Color.RED);
g.fillRect(x,y,w,h);
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_ENTER)
{
y = y+h;
vel = 0;
}
}
}