رسم خطوط مورب زیبا.
با تغییر دادن اندازه ی پنجره ، اندازه ی خطوط به تناسب تغییر می کنه.
این برنامه رو به صورت Applet نوشتم.
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class Lines extends Applet {
int w = 0;
int h = 0;
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;
public void init() {
setSize(800, 600);
setBackground(Color.PINK);
}
public void paint(Graphics g) {
w = getSize().width;
h = getSize().height;
leftDown(g, w, h, w / 30, h / 30);
leftUp(g, w, h, w / 30, h / 30);
rightDown(g, w, h, w / 30, h / 30);
rightUp(g, w, h, w / 30, h / 30);
}
public void leftDown(Graphics g, int w, int h, int wp, int hp) {
x1 = w;
y1 = h;
x2 = 0;
y2 = h;
g.setColor(Color.BLACK); // Drawing line color is red
for (int i = 0; i < w/5; i++) {
g.drawLine(x1, y1, x2, y2);
x1 -= wp;
y2 -= hp;
}
}
public void leftUp(Graphics g, int w, int h, int wp, int hp) {
x1 = w;
y1 = 0;
x2 = 0;
y2 = 0;
g.setColor(Color.BLACK); // Drawing line color is red
for (int i = 0; i < w/5; i++) {
g.drawLine(x1, y1, x2, y2);
x1 -= wp;
y2 += hp;
}
}
public void rightDown(Graphics g, int w, int h, int wp, int hp) {
x1 = 0;
y1 = 0;
x2 = w;
y2 = 0;
g.setColor(Color.BLACK); // Drawing line color is red
for (int i = 0; i < w/5; i++) {
g.drawLine(x1, y1, x2, y2);
x1 += wp;
y2 += hp;
}
}
public void rightUp(Graphics g, int w, int h, int wp, int hp) {
x1 = 0;
y1 = h;
x2 = w;
y2 = h;
g.setColor(Color.BLACK); // Drawing line color is red
for (int i = 0; i < w/5; i++) {
g.drawLine(x1, y1, x2, y2);
x1 += wp;
y2 -= hp;
}
}
}