java小闹钟代码 java闹钟小程序( 六 )


char c;
String getTime = JOptionPane.showInputDialog(this, "请输入闹铃时间格式如:", "00:00");
repaint();
//如果撤消设置时间,就什么打印null
if(getTime==null)
System.out.println(getTime);
//dispose();
judge: if (getTime != null) {
//打印输入的设置的时间
System.out.println(getTime);
// 判断输入的是不是5位字符
if (getTime.length() != 5) {
JOptionPane.showMessageDialog(time, "格式错误\n请按格式输入5位数字", "Error",
JOptionPane.ERROR_MESSAGE);
repaint();
break judge;
}
// 判断输入的是不是数字
for (int i = 0; i(getTime.length()); i++) {
c = getTime.charAt(i);
if (i == 2!Character.isDigit(c))
continue;
// 判断当前字符,如果不是数字则跳出该事件
if (i != 2!Character.isDigit(c)) {
JOptionPane.showMessageDialog(this, "格式错误\n请按格式输入5位数字",
"Error",JOptionPane.ERROR_MESSAGE);
repaint();
break judge;
}
}
char[] hour = { getTime.charAt(0), getTime.charAt(1) };
char[] minute = { getTime.charAt(3), getTime.charAt(4) };
newHou = Integer.parseInt(String.valueOf(hour));
newMin = Integer.parseInt(String.valueOf(minute));
if (newHou = 24 || newHou0) {
JOptionPane.showMessageDialog(this, "格式错误\n小时应该是不小于0不大于23的正数",
"Error", JOptionPane.ERROR_MESSAGE);
repaint();
break judge;
}
if (newMin = 60 || newHou0) {
JOptionPane.showMessageDialog(this, "格式错误\n分钟应该是小于60的正数", "Error",
JOptionPane.ERROR_MESSAGE);
repaint();
break judge;
}
new SetTime(newHou, newMin);
}
}
if (e.getActionCommand() == "ring1") {
toolkit=Toolkit.getDefaultToolkit();
}
if(e.getActionCommand() == "ring2"){
System.out.println("静音");
toolkit=null;
}
if (e.getActionCommand() == "color1") {
String color;
Color c;
System.out.println("color1");
color = JOptionPane.showInputDialog(this, "请输入喜欢的外圈颜色(0--255)", "128");
if (color == null) {
} else {
if (Integer.parseInt(color)0
|| Integer.parseInt(color)255)
JOptionPane.showInputDialog(this, "请输入喜欢的外圈颜色(0--255)", "128");
else {
c = new Color(Integer.parseInt(color));
C1 = c;
}
}
}
if(e.getActionCommand() == "color2"){
String color;
Color c;
System.out.println("color2");
color = JOptionPane.showInputDialog(this, "请输入喜欢的边线颜色(0--255)", "128");
if(color==null){}
else{if (Integer.parseInt(color)0|| Integer.parseInt(color)255)
JOptionPane.showInputDialog(this, "请输入喜欢的边线颜色(0--255)", "128");
else {
c = new Color(Integer.parseInt(color));
C2 = c;
}
}
}
if(e.getActionCommand() == "color3"){
String color;
Color c;
System.out.println("color3");
color = JOptionPane.showInputDialog(this, "请输入喜欢的内盘颜色(0--255)", "128");
if(color==null){}
else{if (Integer.parseInt(color)0|| Integer.parseInt(color)255)
JOptionPane.showInputDialog(this, "请输入喜欢的内盘颜色(0--255)", "128");
else {
c = new Color(Integer.parseInt(color));
C3 = c;
}
}
}
if(e.getActionCommand() == "color4"){
String color;
Color c;
System.out.println("color4");
color = JOptionPane.showInputDialog(this, "请输入喜欢的背景颜色(0--255)", "128");
if(color==null){}
else{if (Integer.parseInt(color)0|| Integer.parseInt(color)255)
JOptionPane.showInputDialog(this, "请输入喜欢的背景颜色(0--255)", "128");
else {
c = new Color(Integer.parseInt(color));

推荐阅读