Programmingbydoing
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的更多相关文章
- 【译】快速高效学习Java编程在线资源Top 20
想要加强你的编程能力吗?想要提升你的 Java 编程技巧和效率吗? 不用担心.本文将会提供快速高效学习 Java 编程的 50 多个网站资源: 开始探索吧: 1.MKyong:许多开发者在这里可以找到 ...
- 快速高效学习Java编程在线资源Top 20(转载)
想要加强你的编程能力吗?想要提升你的 Java 编程技巧和效率吗? 不用担心.本文将会提供快速高效学习 Java 编程的 50 多个网站资源: 开始探索吧: 1.MKyong:许多开发者在这里可以找到 ...
随机推荐
- PostgreSQL中的一些日志
1.Write Ahead Log(WAL日志)预写日志(WAL)是保证数据完整性的标准方法.在有关交易处理的大多数(如果不是全部)书籍中都可以找到详细说明. 简而言之,WAL的核心概念是,只有在记录 ...
- ROS tf-深入Time和TF
博客转载自:https://www.ncnynl.com/archives/201702/1313.html ROS与C++入门教程-tf-深入Time和TF 说明: 介绍使用waitForTrans ...
- RequestUtil 获取网址页面信息
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.i ...
- 【Git】The authenticity of host '192.168.1.1 (192.168.1.1)' can't be established.
背景,在服务器用www用户身份 执行拉取命令报错 sudo -u www git pull 原因分析: 在新生成密钥之后,在.ssh文件夹中少了known_hosts文件 解决办法: Are you ...
- matlab学习笔记5--低级文件输入输出函数
一起来学matlab-matlab学习笔记5 低级文件输入输出函数 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考书籍 <matlab 程序设计与综合应用>张德丰等著 感谢张 ...
- [LeetCode] 259. 3Sum Smaller 三数之和较小值
Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 < ...
- 树莓派插入U盘自动拷贝系统日志到U盘或通过U盘升级程序
注意,U盘用Fat32格式,NTFS格式的话,需要在Linux另外安装相应驱动. 可通过udev实现如题的功能. 在/etc/udev/rules.d/目录下新建规则文件98-logcopy.rule ...
- 使用win10自带虚拟光驱打开ISO镜像文件
使用win10自带虚拟光驱打开ISO镜像文件非常的简单. 工具/原料 电脑 win10系统 方法/步骤 第一种方法,双击ISO文件.打开“我的电脑”,打开所要打开的ISO文件所在的目录,双击要 ...
- 谷歌浏览器调试swoole长连接方法
谷歌浏览器调试swoole长连接方法network标签里面的ws 看frames
- windows10 ubuntu子系统运行docker出现的问题
前一篇笔记记录了安装的过程及错误处理办法,但是在正式使用docker时,却又出现新的问题: “docker: Cannot connect to the Docker daemon at unix:/ ...