⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myframe.java

📁 金旭亮的java教案
💻 JAVA
字号:
// 40 line Java demo, Peter van der Linden
// rolls colored text across the screen
import java.awt.*; 
class myframe extends Frame {
    static int x=0,y=120; // x,y position to display message
    static int i=0; 
    static int horizScroll=1;    // 1->we are moving msg L-to-R

    Font fb = new Font("宋体", Font.BOLD, 36);
    String msg[]={"中国人", "美国佬", "日本鬼子", "德国大兵"}; 
    Color color[]={Color.blue, Color.DARK_GRAY, Color.green, Color.red};

    public void paint(Graphics g) { // gets called by runtime library
        g.setFont( fb );
        g.setColor( color[i] );
        g.drawString(msg[i],x,y);
    }

    static public void main(String s[]) throws Exception {
        myframe mf = new myframe();
        mf.setSize(200,200);
        mf.setLocation(300,300);
        int pixelsPerLine=200, totalLines=4;
        mf.setVisible(true);
        for (int j=0;j<pixelsPerLine*totalLines; j++) {
            Thread.sleep(25); //等待0.25秒
            mf.repaint(); //重绘屏幕
            if (horizScroll==1) { // increase x to scroll horizontally
                if ( (x+=3) < 200) continue;
                i = ++i % 4;        // move index to next msg/color
                x=50; y=0; horizScroll=0;  // scroll vertically next time
            } else { // increase y to scroll vertically
                if ( (y+=3) < 200) continue;
                i = ++i % 4;        // move index to next msg/color
                x=0; y=120; horizScroll=1; // horiz scroll next time
            }
        }
        System.exit(0);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -