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

© samove 中级黑马   /  2015-7-16 22:46  /  2022 人查看  /  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 个回复

正序浏览
楼主精神可嘉
回复 使用道具 举报
写的不错,顶一个
回复 使用道具 举报
lishang 发表于 2015-7-17 23:05
感觉挺nb,不过不知道会不会卡到死

幸福到老死。
回复 使用道具 举报
这是什么,不知道。。。。
回复 使用道具 举报
很厉害的样子。。
回复 使用道具 举报
不明觉厉啊、
回复 使用道具 举报
首先得有个...
回复 使用道具 举报
samove 发表于 2015-7-18 19:46
直接   Import...   到你的  Eclipse  里运行就可以了

哦哦好的
回复 使用道具 举报
zhand 中级黑马 2015-7-18 20:49:55
27#
赞一个 看着挺不错的
回复 使用道具 举报


windows.rar (1.48 KB, 下载次数: 50)

直接   Import...   到你的  Eclipse  里运行就可以了
回复 使用道具 举报
秀丽xl 发表于 2015-7-16 23:30
这个高端呀。。哈哈。。神器呀

唉,可惜啊,,。。。
回复 使用道具 举报
赞!!!!!
回复 使用道具 举报
Claw 中级黑马 2015-7-18 00:12:45
23#
编程思想有点厉害。
楼主加油!
回复 使用道具 举报
教我怎么用行吗
回复 使用道具 举报
赞一个!
回复 使用道具 举报
感觉挺nb,不过不知道会不会卡到死
回复 使用道具 举报
瞬间感觉逼格好高,然并卵
回复 使用道具 举报
孙大神就是不一样!牛逼啊!
回复 使用道具 举报
好嘛,,,,,
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 加入黑马