Biblioteca Java

Subversion Repositories:
Compare Path: Rev
With Path: Rev
/Courses and labs samples/ @ 23  →  /Courses and labs samples/ @ 24
New file
/Courses and labs samples/STR/L2/.classpath
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/>
</classpath>
New file
/Courses and labs samples/STR/L2/.project
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Hello</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
New file
/Courses and labs samples/STR/L2/src/rectangles/move/Main.java
@@ -0,0 +1,14 @@
package rectangles.move;
 
public class Main {
public static void main(String[] args) {
Window w = new Window();
Rectangle r1 = new Rectangle(w, 10, 40, 1);
Rectangle r2 = new Rectangle(w, 10, 100, 2);
w.addRectangle(r1);
w.addRectangle(r2);
r1.start();
r2.start();
}
}
New file
/Courses and labs samples/STR/L2/src/rectangles/move/Rectangle.java
@@ -0,0 +1,36 @@
package rectangles.move;
 
import java.util.Observable;
import java.util.Random;
 
public class Rectangle extends Thread {
int x;
int y;
int prevX;
int speed;
Window w;
public Rectangle(Window w, int x, int y, int speed) {
super();
this.x = x;
this.y = y;
this.speed = speed;
this.w = w;
}
public void run(){
while(x<200){
prevX = x;
x+=speed;
w.repaint();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
New file
/Courses and labs samples/STR/L2/src/rectangles/move/Window.java
@@ -0,0 +1,33 @@
package rectangles.move;
 
import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
 
import javax.swing.JFrame;
import javax.swing.JProgressBar;
 
public class Window extends JFrame {
ArrayList<Rectangle> list = new ArrayList<Rectangle>();
 
public Window() {
setLayout(null);
setSize(450, 400);
setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
void addRectangle(Rectangle r){
list.add(r);
}
 
public void paint(Graphics g){
if(list!=null)
for(Rectangle r: list ){
g.setColor(Color.white);
g.fillRect(r.prevX, r.y, 30, 30);
g.setColor(Color.black);
g.fillRect(r.x, r.y, 30, 30);
}
}
}