package Chapter03;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.swing.JOptionPane;
public class chapter03_example01 {
public static void main(String[] args) {
//booleantypetest();
//dateshijianxianshi();
//lianggeshuxiangjia();
//randomexercise();
//switchyuju();
confirmed();
}
public static void booleantypetest() {
boolean right = true, wrong = false;
char c1 = 'a', c2 = 'A';
if (c1 > c2) {
System.out.println("a > A is " + right);
System.out.println(c1 + "\t" + (int) c1);
System.out.println(c2 + "\t" + (int) c2);
} else
System.out.println("a > A is " + wrong);
System.out.println(2 < 0);// 输出boolean类型结果
int xx = 101;
boolean even1 = true;
if (xx % 2 == 0)
even1 = true;
else
even1 = false;
System.out.println("even1 = " + even1);
// 可以代替上面的if语句判断,将判断结果直接赋值到boolean类型的变量中。
boolean even2 = xx % 2 == 0;
System.out.println("even2 = " + even2);
}
public static void dateshijianxianshi(){
/*
* System.currentTimeMillis()产生一个当前的毫秒,这个毫秒其实就是自1970年1月1日0时起的毫秒数
* Date();
* */
Date nowtime = new Date(System.currentTimeMillis());
SimpleDateFormat dateformat = new SimpleDateFormat("z:y-MM-dd kk:mm:ss");
String datenow = dateformat.format(nowtime);
System.out.println(datenow);
}
public static void lianggeshuxiangjia() {
System.out.println(System.currentTimeMillis());
int number1 = (int) (System.currentTimeMillis() % 10);
int number2 = (int) (System.currentTimeMillis() * 7 % 10);
String output = number1 + " + " + number2 + " = ?";
String answerString = JOptionPane.showInputDialog(null, output, "两个数的和", JOptionPane.QUESTION_MESSAGE);
int answer = Integer.parseInt(answerString);
String output2 = number1 + " + " + number2 + " = " + (number1 + number2);
String output3 = number1 + " + " + number2 + " != " + answer;
if ((number1 + number2) == answer) {
JOptionPane.showMessageDialog(null, "回答正确!\n" + output2, "结果判断", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "回答错误!\n" + output3 + "\n正确答案是\n" + output2, "结果判断",
JOptionPane.INFORMATION_MESSAGE);
}
}
public static void randomexercise(){
double xx = Math.random();
System.out.println(xx);
int number1 = (int)(Math.random()*100%10);
int number2 = (int)(Math.random()*100%10);
String output1 = number1 + " + " +number2;
String answerString = JOptionPane.showInputDialog(null,output1 + " = ?","问题",JOptionPane.QUESTION_MESSAGE);
int answer1 = Integer.parseInt(answerString);
int answer2 = number1 + number2;
if(answer1 == answer2){
JOptionPane.showMessageDialog(null, output1+" = " + answer2, "正确", JOptionPane.INFORMATION_MESSAGE);
}else{
JOptionPane.showMessageDialog(null, output1 + " != " + answer1, "错误", JOptionPane.INFORMATION_MESSAGE);
}
}
public static void switchyuju(){
int number1 = 90;
switch(number1)
{
case 10: System.out.println("case 10");
break;
case 100: System.out.println("case 100");
break;
default: System.out.println("no case");
System.exit(0);
}
}
//(GUI)确认对话框
public static void confirmed(){
int confirm = JOptionPane.showConfirmDialog(null, "confirmed?", "标题", JOptionPane.INFORMATION_MESSAGE);
System.out.println(confirm);
System.out.println(JOptionPane.YES_OPTION);
}
}
简单代码gui确认对话框_20160909
最新推荐文章于 2020-12-28 21:45:26 发布