- <div class="blockcode"><blockquote><div class="blockcode"><blockquote>public class LoveStory {
- public static void main(String[] args) {
- String[] st = { "如", "果", "上", "天", "能", "够", "给", "我", "一", "个", "再",
- "来", "一", "次", "的", "机", "会", ",", "我", "会", "对", "那", "个",
- "女", "孩", "子", "说", "三", "个", "字", ":", "我", "爱", "你", "。",
- "如", "果", "非", "要", "在", "这", "份", "爱", "上", "加", "上", "一",
- "个", "期", "限", ",", "我", "希", "望", "是", "…", "…", "一", "万",
- "年", "…"};
- int sizeX = 200;
- int sizeY = 200;
- int locationX = 0;
- int locationY = 0;
- long lo1 = System.currentTimeMillis();
- long lo2 = lo1;
- int i = 0;
- int x = 0;
- int y = 1400;
- int z = 800;
- int count = 0;
- boolean b = false;
- A: while (true) {
- lo2 = System.currentTimeMillis();
- if (lo2 - lo1 > 250) {
- lo1 = lo2;
- if (i >= st.length) {
- System.exit(0);
- }
- @SuppressWarnings("unused")
- MyJFrame mf = new MyJFrame(sizeX, sizeY, locationX, locationY,
- st[i]);
- locationX += 200;
- if (locationX >= y ) {
- locationX = x;
- locationY += 200;
- if (locationY >= z && !b) {
- x = 50;
- locationX = x;
- y = 1200;
- locationY = 50;
- z = 600 ;
- count++;
- if (count == 2) {
- b = true;
- }
- }
- if (b) {
- x = 100;
- locationX = x;
- y = 1000;
- locationY = 100;
- b = false;
- }
- }
- i++;
- continue A;
- }
- }
- }
- }
复制代码
import java.awt.Canvas;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
public class MyCanvas extends Canvas {
/**
*
*/
private static final long serialVersionUID = 1L;
private String string;
public MyCanvas (String string){
this.string = string;
}
@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
g2.setFont( new Font("宋体", Font.BOLD, 100)); // 设置字体
g2.drawString(string, 40, 110); // 绘制文本
}
}
import javax.swing.JFrame;
public class MyJFrame extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
private String string;
public MyJFrame(int sizeX, int sizeY, int locationX, int locationY, String string){
this.string = string;
this.setTitle("表白神器");
this.setSize(sizeX, sizeY);
this.setLocation(locationX, locationY);
add(new MyCanvas(string));
this.setVisible(true);
}
}
表白神器!
等明天学到 IO 读写文件,就可以直接从TXT文件里读取文本,输出了。
关于JFrame,GUI这东东,是看书自学了一点。
|
|