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大作业题目有哪些的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- 手机服务密码怎么查询密码,手机服务密码咋查
- ios未越狱有什么gba,未越狱的苹果手机是什么意思
- oracle安装和创建用户,oracle安装创建用户失败
- 角色扮演国风类武侠游戏,国风角色扮演类手游
- java下载图片代码 java下载图片保存到指定目录下
- 阿里mysql并发设置,mysql并发连接数设置
- 养成系列游戏,养成系列游戏排行榜
- 最新卖衣服直播平台,最新卖衣服直播平台有哪些
- go语言切片数组 go语言切片删除元素