public class Chooser extends JPanel{ private static final long serialVersionUID = -5384012731547358720L; private Calendar calendar; private Calendar now = Calendar.getInstance(); private JPanel calendarPanel; private java.awt.Font font = new java.awt.Font("Times",java.awt.Font.PLAIN,12); private java.text.SimpleDateFormat sdf; private final LabelManager lm = new LabelManager(); private javax.swing.Popup pop; private TitlePanel titlePanel; private BodyPanel bodyPanel; private FooterPanel footerPanel; private JComponent showDate; private boolean isShow = false; private static final String DEFAULTFORMAT = "yyyy-MM-dd"; private static final String[] showTEXT = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; private static WeekLabel[] weekLabels = new WeekLabel[7]; private static int defaultStartDAY = 0;//0 is from Sun, 1 is from Mon, 2 is from Tue private static Color hoverColor = Color.BLUE; // hover color private Chooser(java.util.Date date, String format, int startDAY){ if(startDAY > -1 && startDAY < 7) defaultStartDAY = startDAY; int dayIndex = defaultStartDAY; for(int i=0; i<7; i++){ if(dayIndex > 6) dayIndex = 0; weekLabels[i] = new WeekLabel(dayIndex, showTEXT[dayIndex]); dayIndex ++ ; } sdf = new java.text.SimpleDateFormat(format); calendar = Calendar.getInstance(); calendar.setTime(date); initCalendarPanel(); } 分析每一句

时间: 2024-01-29 09:02:24 浏览: 33
1. `public class Chooser extends JPanel{`: 定义一个名为 `Chooser` 的类,继承自 `JPanel` 类。 2. `private static final long serialVersionUID = -5384012731547358720L;`: 定义一个私有的、静态的、常量类型的变量 `serialVersionUID`,用于序列化和反序列化对象。 3. `private Calendar calendar;`: 定义一个私有的 `Calendar` 类型的变量 `calendar`。 4. `private Calendar now = Calendar.getInstance();`: 定义一个私有的 `Calendar` 类型的变量 `now`,并将其初始化为当前时间。 5. `private JPanel calendarPanel;`: 定义一个私有的 `JPanel` 类型的变量 `calendarPanel`。 6. `private java.awt.Font font = new java.awt.Font("Times",java.awt.Font.PLAIN,12);`: 定义一个私有的 `java.awt.Font` 类型的变量 `font`,并将其初始化为字体为 Times,风格为普通,大小为 12。 7. `private java.text.SimpleDateFormat sdf;`: 定义一个私有的 `java.text.SimpleDateFormat` 类型的变量 `sdf`。 8. `private final LabelManager lm = new LabelManager();`: 定义一个私有的、不可变的 `LabelManager` 类型的变量 `lm`,并将其初始化。 9. `private javax.swing.Popup pop;`: 定义一个私有的 `javax.swing.Popup` 类型的变量 `pop`。 10. `private TitlePanel titlePanel;`: 定义一个私有的 `TitlePanel` 类型的变量 `titlePanel`。 11. `private BodyPanel bodyPanel;`: 定义一个私有的 `BodyPanel` 类型的变量 `bodyPanel`。 12. `private FooterPanel footerPanel;`: 定义一个私有的 `FooterPanel` 类型的变量 `footerPanel`。 13. `private JComponent showDate;`: 定义一个私有的 `JComponent` 类型的变量 `showDate`。 14. `private boolean isShow = false;`: 定义一个私有的、布尔类型的变量 `isShow`,并将其初始化为 `false`。 15. `private static final String DEFAULTFORMAT = "yyyy-MM-dd";`: 定义一个私有的、静态的、常量类型的字符串变量 `DEFAULTFORMAT`,并将其初始化为字符串 "yyyy-MM-dd"。 16. `private static final String[] showTEXT = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};`: 定义一个私有的、静态的、常量类型的字符串数组 `showTEXT`,并将其初始化为包含星期日到星期六的字符串数组。 17. `private static WeekLabel[] weekLabels = new WeekLabel[7];`: 定义一个私有的、静态的、长度为 7 的 `WeekLabel` 类型的数组 `weekLabels`。 18. `private static int defaultStartDAY = 0;//0 is from Sun, 1 is from Mon, 2 is from Tue`: 定义一个私有的、静态的、整型变量 `defaultStartDAY`,并将其初始化为 0,表示星期日是一周的第一天。 19. `private static Color hoverColor = Color.BLUE; // hover color`: 定义一个私有的、静态的、`Color` 类型的变量 `hoverColor`,并将其初始化为蓝色。 20. `private Chooser(java.util.Date date, String format, int startDAY){`: 定义一个构造函数 `Chooser`,参数为一个 `java.util.Date` 类型的变量 `date`,一个字符串类型的变量 `format` 和一个整型变量 `startDAY`。 21. `if(startDAY > -1 && startDAY < 7) defaultStartDAY = startDAY;`: 如果 `startDAY` 的值大于 -1 并且小于 7,则将 `defaultStartDAY` 的值设置为 `startDAY`。 22. `int dayIndex = defaultStartDAY;`: 定义一个整型变量 `dayIndex`,并将其初始化为 `defaultStartDAY`。 23. `for(int i=0; i<7; i++){`: 循环 7 次。 24. `if(dayIndex > 6) dayIndex = 0;`: 如果 `dayIndex` 的值大于 6,则将其重置为 0。 25. `weekLabels[i] = new WeekLabel(dayIndex, showTEXT[dayIndex]);`: 将 `weekLabels` 数组的第 i 个元素初始化为一个 `WeekLabel` 类型的对象,参数为 `dayIndex` 和 `showTEXT[dayIndex]`。 26. `dayIndex ++ ;`: 将 `dayIndex` 的值加 1。 27. `}`: 结束循环。 28. `sdf = new java.text.SimpleDateFormat(format);`: 将 `sdf` 初始化为一个 `java.text.SimpleDateFormat` 类型的对象,参数为 `format`。 29. `calendar = Calendar.getInstance();`: 将 `calendar` 初始化为一个 `Calendar` 类型的对象,表示当前时间。 30. `calendar.setTime(date);`: 将 `calendar` 对象设置为 `date` 所表示的时间。 31. `initCalendarPanel();`: 调用 `initCalendarPanel()` 方法,初始化日历面板。

相关推荐

private Chooser(java.util.Date date, String format, int startDAY){ if(startDAY > -1 && startDAY < 7) defaultStartDAY = startDAY; int dayIndex = defaultStartDAY; for(int i=0; i<7; i++){ if(dayIndex > 6) dayIndex = 0; weekLabels[i] = new WeekLabel(dayIndex, showTEXT[dayIndex]); dayIndex ++ ; } sdf = new java.text.SimpleDateFormat(format); calendar = Calendar.getInstance(); calendar.setTime(date); initCalendarPanel(); } public static Chooser getInstance(java.util.Date date, String format){ return new Chooser(date, format, defaultStartDAY); } public static Chooser getInstance(java.util.Date date){ return getInstance(date, DEFAULTFORMAT); } public static Chooser getInstance(String format){ return getInstance(new java.util.Date(), format); } public static Chooser getInstance(){ return getInstance(new java.util.Date(), DEFAULTFORMAT); } private void initCalendarPanel(){ calendarPanel = new JPanel(new java.awt.BorderLayout()); calendarPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0xAA, 0xAA, 0xAA))); calendarPanel.add(titlePanel = new TitlePanel(), java.awt.BorderLayout.NORTH); calendarPanel.add(bodyPanel = new BodyPanel(), java.awt.BorderLayout.CENTER); calendarPanel.add(footerPanel = new FooterPanel(),java.awt.BorderLayout.SOUTH); this.addAncestorListener(new AncestorListener() { public void ancestorAdded(AncestorEvent event) { } public void ancestorRemoved(AncestorEvent event) {hidePanel();} //hide pop when move component. public void ancestorMoved(AncestorEvent event) { hidePanel(); } }); } public void register(final JComponent showComponent) { this.showDate = showComponent; showComponent.setRequestFocusEnabled(true); showComponent.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { showComponent.requestFocusInWindow(); } }); this.add(showComponent, BorderLayout.CENTER); this.setPreferredSize(new Dimension(90, 25)); this.setBorder(BorderFactory.createLineBorder(Color.GRAY)); showComponent.addMouseListener(new MouseAdapter() { public void mouseEntered(MouseEvent me) { if (showComponent.isEnabled()) { showComponent.setCursor(new Cursor(Cursor.HAND_CURSOR)); } } public void mouseExited(MouseEvent me) { if (showComponent.isEnabled()) { showComponent.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); showComponent.setForeground(Color.BLACK); } } public void mousePressed(MouseEvent me) { if (showComponent.isEnabled()) { showComponent.setForeground(hoverColor); if (isShow) { hidePanel(); } else { showPanel(showComponent); } } } public void mouseReleased(MouseEvent me) { if (showComponent.isEnabled()) { showComponent.setForeground(Color.BLACK); } } }); showComponent.addFocusListener(new FocusListener() { public void focusLost(FocusEvent e) { hidePanel(); } public void focusGained(FocusEvent e) { } }); } //hide the main panel. private void hidePanel() { if (pop != null) { isShow = false; pop.hide(); pop = null; } }逐行解释

FileSystemView fileSystemView=FileSystemView.getFileSystemView(); File tempFile; if (filepath==null||filepath.isEmpty()||filepath.equals("")) { tempFile=fileSystemView.getHomeDirectory(); }else { tempFile=new File(filepath); } JFileChooser chooser = new JFileChooser(tempFile); //设置选择器 chooser.setMultiSelectionEnabled(true); //设为多选 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);//设置可选择的为文件和文件夹 chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() { @Override public String getDescription() { // TODO Auto-generated method stub return ".xml"; } @Override public boolean accept(File f) { // TODO Auto-generated method stub if (f.getName().toLowerCase().endsWith(".xml")) { return true; } return false; } }); chooser.setDialogTitle("请选择需要修改的文件"); chooser.setPreferredSize(new Dimension(800,1000)); chooser.getActionMap().get("viewTypeDetails").actionPerformed(null); chooser.showOpenDialog(button); //显示打开文件选择框 filepath = chooser.getSelectedFile().getAbsolutePath(); //获取绝对路径 button.setText(filepath); if (chooser.isFileSelectionEnabled()) { new MyJOptionPane("目前仅支持修改xml格式文件,请选择正确的格式"); } if(chooser.isDirectorySelectionEnabled()) { progressBar.setIndeterminate(true); progressBar.setStringPainted(false); progressDialog.setVisible(true); Thread thread=new Thread(() -> { try { XmlHanding.getMyFlie(new File(filepath)); text.setText("已选择文件夹:"+filepath); text.append("\n"+"文件包含"+XmlHanding.fList.size()+"个xml文件"); for(File f:XmlHanding.fList){ text1.append("\n"+f.getAbsolutePath()); } text1.setCaretPosition(0); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); }finally { // 执行完毕后关闭进度对话框 progressDialog.dispose(); } }); thread.start(); } }为什么选择了单个的文件 text还是会写入"已选择文件夹:"+filepath

最新推荐

recommend-type

Java中文件选择器JFileChooser.showSaveDialog实现默认文件名的解决方案

Java中文件选择器JFileChooser.showSaveDialog实现默认文件名的解决方案
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

深入了解MATLAB开根号的最新研究和应用:获取开根号领域的最新动态

![matlab开根号](https://www.mathworks.com/discovery/image-segmentation/_jcr_content/mainParsys3/discoverysubsection_1185333930/mainParsys3/image_copy.adapt.full.medium.jpg/1712813808277.jpg) # 1. MATLAB开根号的理论基础 开根号运算在数学和科学计算中无处不在。在MATLAB中,开根号可以通过多种函数实现,包括`sqrt()`和`nthroot()`。`sqrt()`函数用于计算正实数的平方根,而`nt
recommend-type

react的函数组件的使用

React 的函数组件是一种简单的组件类型,用于定义无状态或者只读组件。 它们通常接受一个 props 对象作为参数并返回一个 React 元素。 函数组件的优点是代码简洁、易于测试和重用,并且它们使 React 应用程序的性能更加出色。 您可以使用函数组件来呈现简单的 UI 组件,例如按钮、菜单、标签或其他部件。 您还可以将它们与 React 中的其他组件类型(如类组件或 Hooks)结合使用,以实现更复杂的 UI 交互和功能。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

解决MATLAB开根号常见问题:提供开根号运算的解决方案

![解决MATLAB开根号常见问题:提供开根号运算的解决方案](https://img-blog.csdnimg.cn/d939d1781acc404d8c826e8af207e68f.png) # 1. MATLAB开根号运算基础** MATLAB开根号运算用于计算一个数的平方根。其语法为: ``` y = sqrt(x) ``` 其中: * `x`:要开根号的数或数组 * `y`:开根号的结果 开根号运算的输入可以是实数、复数、矩阵或数组。对于实数,开根号运算返回一个非负实数。对于复数,开根号运算返回一个复数。对于矩阵或数组,开根号运算逐元素执行,对每个元素进行开根号运算。 #
recommend-type

inputstream

Inputstream是Java中用于从输入流中读取数据的抽象类,它是Java I/O类库中的一部分。Inputstream提供了read()和read(byte[] b)等方法,可以从输入流中读取一个字节或一组字节。在Java中,FileInputStream、ByteArrayInputStream和StringBufferInputStream都是Inputstream的子类,用于读取不同类型的输入流。
recommend-type

c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf

校园超市商品信息管理系统课程设计旨在帮助学生深入理解程序设计的基础知识,同时锻炼他们的实际操作能力。通过设计和实现一个校园超市商品信息管理系统,学生掌握了如何利用计算机科学与技术知识解决实际问题的能力。在课程设计过程中,学生需要对超市商品和销售员的关系进行有效管理,使系统功能更全面、实用,从而提高用户体验和便利性。 学生在课程设计过程中展现了积极的学习态度和纪律,没有缺勤情况,演示过程流畅且作品具有很强的使用价值。设计报告完整详细,展现了对问题的深入思考和解决能力。在答辩环节中,学生能够自信地回答问题,展示出扎实的专业知识和逻辑思维能力。教师对学生的表现予以肯定,认为学生在课程设计中表现出色,值得称赞。 整个课程设计过程包括平时成绩、报告成绩和演示与答辩成绩三个部分,其中平时表现占比20%,报告成绩占比40%,演示与答辩成绩占比40%。通过这三个部分的综合评定,最终为学生总成绩提供参考。总评分以百分制计算,全面评估学生在课程设计中的各项表现,最终为学生提供综合评价和反馈意见。 通过校园超市商品信息管理系统课程设计,学生不仅提升了对程序设计基础知识的理解与应用能力,同时也增强了团队协作和沟通能力。这一过程旨在培养学生综合运用技术解决问题的能力,为其未来的专业发展打下坚实基础。学生在进行校园超市商品信息管理系统课程设计过程中,不仅获得了理论知识的提升,同时也锻炼了实践能力和创新思维,为其未来的职业发展奠定了坚实基础。 校园超市商品信息管理系统课程设计的目的在于促进学生对程序设计基础知识的深入理解与掌握,同时培养学生解决实际问题的能力。通过对系统功能和用户需求的全面考量,学生设计了一个实用、高效的校园超市商品信息管理系统,为用户提供了更便捷、更高效的管理和使用体验。 综上所述,校园超市商品信息管理系统课程设计是一项旨在提升学生综合能力和实践技能的重要教学活动。通过此次设计,学生不仅深化了对程序设计基础知识的理解,还培养了解决实际问题的能力和团队合作精神。这一过程将为学生未来的专业发展提供坚实基础,使其在实际工作中能够胜任更多挑战。