This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OnlyYou | |
{ | |
//构造函数 | |
private OnlyYou() | |
{ | |
} | |
//注意类型是 OnlyYou,并且是静态的 | |
private static OnlyYou obj = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class Form2 : Form | |
{ | |
//唯一实例 | |
private static Form2 obj = null; | |
private Form2() | |
{ | |
//初始化控件(自动生成) | |
InitializeComponent(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void Form2_FormClosing(object sender, FormClosingEventArgs e) | |
{ | |
e.Cancel = (MessageBox.Show("Sure?", | |
"Exit", | |
MessageBoxButtons.YesNo, | |
MessageBoxIcon.Question) == DialogResult.Yes); | |
DialogResult result = MessageBox.Show("提示", "确定退出吗?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); | |
if (result == DialogResult.Yes) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void shuffle(Object[] a) { | |
//判断数组 a 是否可以转为整型数组 | |
validateNotNull(a); | |
int n = a.length; | |
for (int i = 0; i < n; i++) { | |
int r = i + uniform(n-i); // between i and n-1 | |
Object temp = a[i]; | |
a[i] = a[r]; | |
a[r] = temp; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Form1() | |
{ | |
//TimerCallback 是委托类型,可以关联一个形参为 Object 的函数 | |
TimerCallback timerCallback = new TimerCallback(timeUpdate); | |
//Timer 每隔 1000ms 调用委托 | |
System.Threading.Timer timer = new System.Threading.Timer(timerCallback, "", 0, 1000); | |
} | |
public void timeUpdate(Object obj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//读 | |
btn1.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent intent = new Intent(MainActivity.this, WizardOne.class); | |
intent.putExtra("setting", setting); | |
startActivityForResult(intent, 1); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
btnFinish.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent intentToFinish = new Intent(WizardThree.this, FinishActivity.class); | |
//重点是下面这一句 | |
intentToFinish.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); | |
intentToFinish.putExtra("setting", setting); | |
startActivity(intentToFinish); | |
WizardThree.this.finish(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chapter3; | |
/** | |
* @program: studythread2 | |
* @description: synchronized Demo | |
* @author: diaolizhi | |
* @create: 2018-11-13 10:29 | |
**/ | |
public class SynchronizedDemo { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chapter3; | |
/** | |
* @program: studythread2 | |
* @description: 懒汉式单例模式 | |
* @author: diaolizhi | |
* @create: 2018-11-13 12:39 | |
**/ | |
public class LazySingleton { |