http://www.programmingbydoing.com/

1. Modulus Animation

 public static void modulusAnimation() throws InterruptedException {
int repeats = 5;
int steps_per_seconds = 10;
for(int i=0; i<repeats*11; i++){
if(i%11==0){
System.out.println(",oOo.....");
} else if (i%11==1){
System.out.println("..oOo....");
}else if (i%11==2){
System.out.println("...oOo...");
}else if (i%11==3){
System.out.println("....oOo..");
}else if (i%11==4){
System.out.println(".....oOo.");
}else if (i%11==5){
System.out.println("......oOo");
}else if (i%11==6){
System.out.println(".........oO");
}else if (i%11==7){
System.out.println("o.......o");
}else if (i%11==8){
System.out.println("Oo.......");
}else if (i%11==9){
System.out.println("oOo......");
}else if (i%11==10){
System.out.println(".oOo.....");
}else if (i%11==11){
System.out.println("..oOo....");
} Thread.sleep(1000/steps_per_seconds);
}
}

2.Using swing for input

 public static void inputBox(){
String name = JOptionPane.showInputDialog("What's your name?");
String input = JOptionPane.showInputDialog("How old are you");
int age = Integer.parseInt(input); System.out.println("Hello, " + name);
System.out.println("Next year, you will be " + (age+1));
System.exit(0);
}

3. A frame with a Panel with writing on it

import javax.swing.*;
import java.awt.*; public class Prog613 {
public static void main(String[] args) {
Frame613 f = new Frame613();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
} class Frame613 extends JFrame {
public Frame613(){
setTitle("613 rocks");
setSize(300,200);
setLocation(100,200); Panel613 panel = new Panel613();
Container cp = getContentPane();
cp.add(panel);
}
} class Panel613 extends JPanel{
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawString("Hi, ",75, 100);
} }

4. Graphics Demo1

import javax.swing.*;
import java.awt.*; public class GraphicsDemo1 extends Canvas {
public static void main(String[] args) {
JFrame win = new JFrame("GraphicsDemo1");
win.setSize(600,800);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GraphicsDemo1 canvas = new GraphicsDemo1();
win.add(canvas);
win.setVisible(true);
} public void paint(Graphics g){
g.setColor(Color.green);
g.drawRect(50,20,100,200);
g.fillOval(160,20,100,200);
g.setColor(Color.blue);
g.fillRect(200,400,200,20);
g.drawOval(200,430,200,100); g.setColor(Color.black);
g.drawString("Graphics are pretty neat. ",500,100);
int x = getWidth()/2;
int y = getHeight()/2;
g.drawString("The first letter of this string is at (" + x + ","+y+")",x,y); } }

Programmingbydoing的更多相关文章

  1. 【译】快速高效学习Java编程在线资源Top 20

    想要加强你的编程能力吗?想要提升你的 Java 编程技巧和效率吗? 不用担心.本文将会提供快速高效学习 Java 编程的 50 多个网站资源: 开始探索吧: 1.MKyong:许多开发者在这里可以找到 ...

  2. 快速高效学习Java编程在线资源Top 20(转载)

    想要加强你的编程能力吗?想要提升你的 Java 编程技巧和效率吗? 不用担心.本文将会提供快速高效学习 Java 编程的 50 多个网站资源: 开始探索吧: 1.MKyong:许多开发者在这里可以找到 ...

随机推荐

  1. jmeter cookie管理器

    jmeter cookie管理器 不能用正则表达式获取登录接口生成的cookie 因为cookies并不是在登录的响应结果中生成的,而是在response header中携带的,所以不能用正则表达式提 ...

  2. 上传图片 展示进度条 bootstrap

    <!DOCTYPE html><html><head> <meta charset="utf-8"> <title>Bo ...

  3. IfcWallStandardCase 构件吊装模拟

    wall_node = (osg::Node*)(index_node->clone(osg::CopyOp::DEEP_COPY_ALL));vc_mobileCrane->tranMo ...

  4. Shell中的通配符

    shell常见的通配符,注意与正则稍有不同: 字符 含义 实例 * 匹配0个或多个任意字符 a*b,a与b之间可以有任意长度的字符,也可以没有. 例如:aabcb,ab,azxcb... ? 匹配一个 ...

  5. Pytest单元测试框架-测试用例运行规则

    1.Pytest测试用例运行规则 在pytest单元测试框架下面执行用例,需要满足以下几个特点: 1. 文件名以test_*.py开头或者*_test.py 2. 测试类.测试函数以test开头 3. ...

  6. [LeetCode] 624. Maximum Distance in Arrays 数组中的最大距离

    Given m arrays, and each array is sorted in ascending order. Now you can pick up two integers from t ...

  7. Python 安装 MySQL-python ImportError: No module named 'ConfigParser'

    系统: CentOS-6.4-x86_64 Python : Python 3.4.5 和 Python 3.5.2 安装 MySQL-python ,结果出错: ImportError: No mo ...

  8. consul reconnect_timeout

    reconnect_timeout这将控制从集群中彻底删除发生故障的节点需要多长时间.默认值为72小时,建议将其设置为至少为节点或网络分区的预期可恢复的最大停机时间的两倍.警告:将此时间设置得太低可能 ...

  9. Java程序运行机制

    Java程序运行机制 编译型(compile) 它有一个负责翻译的程序(编译器),将我们写的 Java 源代码转为计算机可执行的代码 举个例子:把一本中文书翻译成英文书 应用:操作系统.C.C++ 解 ...

  10. POJ 2106 Boolean Expressions

    总时间限制: 1000ms  内存限制: 65536kB 描述 The objective of the program you are going to produce is to evaluate ...