java大作业源代码 java大作业题目有哪些( 八 )


panel.add(userText);
// 创建 JLabel
JLabel showLable = new JLabel();
showLable.setBounds(5, 70, 300, 25);
panel.add(showLable);
// 创建登录按钮
JButton loginButton = new JButton("转换");
loginButton.setBounds(180, 40, 100, 25);
loginButton.addActionListener(new ActionListener() {
DateFormat input = new SimpleDateFormat("yyyy-MM-dd");
DateFormat output = new SimpleDateFormat("yyyy年MM月dd日");
{
input.setLenient(false);// 设置严格按格式匹配
output.setLenient(false);
}
@Override
public void actionPerformed(ActionEvent actionEvent) {
try {
Date date = convert(userText.getText());
showLable.setText("成功:" + output.format(date));
showLable.setForeground(Color.GREEN);
} catch (WrongDateException e) {
showLable.setText(e.getMessage());
showLable.setForeground(Color.RED);
}
}
private Date convert(String text) throws WrongDateException {
try {
return input.parse(text);
} catch (ParseException e) {
throw new WrongDateException(text);
}
}
});
panel.add(loginButton);
}
static class WrongDateException extends Exception {
WrongDateException(String s) {
super(s + "不是合法的日期字符串");
}
}
}
【java大作业源代码 java大作业题目有哪些】关于java大作业源代码和java大作业题目有哪些的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读