A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© samove 中级黑马   /  2015-7-16 22:46  /  1722 人查看  /  37 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. <div class="blockcode"><blockquote><div class="blockcode"><blockquote>public class LoveStory {
  2.         public static void main(String[] args) {
  3.                 String[] st = { "如", "果", "上", "天", "能", "够", "给", "我", "一", "个", "再",
  4.                                 "来", "一", "次", "的", "机", "会", ",", "我", "会", "对", "那", "个",
  5.                                 "女", "孩", "子", "说", "三", "个", "字", ":", "我", "爱", "你", "。",
  6.                                 "如", "果", "非", "要", "在", "这", "份", "爱", "上", "加", "上", "一",
  7.                                 "个", "期", "限", ",", "我", "希", "望", "是", "…", "…", "一", "万",
  8.                                 "年", "…"};
  9.                 int sizeX = 200;
  10.                 int sizeY = 200;
  11.                 int locationX = 0;
  12.                 int locationY = 0;
  13.                 long lo1 = System.currentTimeMillis();
  14.                 long lo2 = lo1;
  15.                 int i = 0;
  16.                 int x = 0;
  17.                 int y = 1400;
  18.                 int z = 800;
  19.                 int count = 0;
  20.                 boolean b = false;
  21.                 A: while (true) {
  22.                         lo2 = System.currentTimeMillis();
  23.                         if (lo2 - lo1 > 250) {
  24.                                 lo1 = lo2;
  25.                                 if (i >= st.length) {
  26.                                         System.exit(0);
  27.                                 }
  28.                                 @SuppressWarnings("unused")
  29.                                 MyJFrame mf = new MyJFrame(sizeX, sizeY, locationX, locationY,
  30.                                                 st[i]);
  31.                                 locationX += 200;
  32.                                 if (locationX >= y ) {
  33.                                         locationX = x;
  34.                                         locationY += 200;
  35.                                         if (locationY >= z && !b) {
  36.                                                 x = 50;
  37.                                                 locationX = x;
  38.                                                 y = 1200;
  39.                                                 locationY = 50;
  40.                                                 z = 600 ;
  41.                                                 count++;
  42.                                                 if (count == 2) {
  43.                                                         b = true;
  44.                                                 }
  45.                                         }
  46.                                         if (b) {
  47.                                                 x = 100;
  48.                                                 locationX = x;
  49.                                                 y = 1000;
  50.                                                 locationY = 100;
  51.                                                 b = false;
  52.                                         }
  53.                                 }

  54.                                 i++;
  55.                                 continue A;
  56.                         }
  57.                 }
  58.         }
  59. }
复制代码

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这东东,是看书自学了一点。

37 个回复

倒序浏览
吃惊                                         
回复 使用道具 举报
这个真高级
回复 使用道具 举报
这个高端呀。。哈哈。。神器呀
回复 使用道具 举报
这个好牛逼啊,然并卵啊
回复 使用道具 举报
好像是很高大上的样子勒!!!!!!!!!!
回复 使用道具 举报
蔡锐 中级黑马 2015-7-17 08:30:35
7#
完全没有注释,不明觉厉
回复 使用道具 举报
然而你懂的
回复 使用道具 举报
我想知道我电脑会不会卡爆,一万年  万字卡了  变一年咋弄:lol
回复 使用道具 举报
反正我看不懂
回复 使用道具 举报
呵呵   的确是神器,
回复 使用道具 举报
哇哦     :o
回复 使用道具 举报
好厉害的样子..
回复 使用道具 举报
好高大上啊 ,收下了
回复 使用道具 举报
让女朋友运行该程序,退出不了,,结果电脑被卡坏,

点评

先嘚有女朋友才行啊、、我这个只能给自己new出来的对象看。  发表于 2015-7-18 19:50
回复 使用道具 举报
好像很厉害的样子。。
回复 使用道具 举报
好嘛,,,,,
回复 使用道具 举报
孙大神就是不一样!牛逼啊!
回复 使用道具 举报
瞬间感觉逼格好高,然并卵
回复 使用道具 举报
感觉挺nb,不过不知道会不会卡到死

点评

想怎么死都行,你选吧 ^_^  发表于 2015-7-18 19:51
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 加入黑马