ImageVerifierCode 换一换
格式:DOCX , 页数:12 ,大小:52.29KB ,
资源ID:18031401      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/18031401.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(windows日历时钟文档格式.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

windows日历时钟文档格式.docx

1、 JPanel timeArea=new JPanel(); /Internet时间 JPanel internetTime=new JPanel(); /创建属性页tabbedPane JTabbedPane tabbedPane=new JTabbedPane(); tabbedPane.addTab(时间和日期, dt);时区, timeArea);Internet时间, internetTime); tabbedPane.setSelectedIndex(0); /设置默认版位第一版 getContentPane().add(tabbedPane,BorderLayout.CENTER

2、); /把属性页加到frame中去 public static void main(String args) JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame=new main0(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); frame.setSize(400,250);Rili.javaimport java.awt.event.*;import java.util.*;import

3、javax.swing.event.*;import javax.swing.table.*;public class rili extends JApplet /*定义全局变量*/ public static final Color background = Color.white;/背景色 public static final Color foreground = Color.black;/前景色 public static final Color headerBackground = Color.DARK_GRAY;/星期 public static final Color heade

4、rForeground = Color.white;/星期前景色 public static final Color selectedBackground = Color.blue;/选中背景色 public static final Color selectedForeground = Color.white;/选中前景色 public static final String WeekSun = 日; /星期标签名称 public static final String WeekMon = 一 public static final String WeekTue = 二 public sta

5、tic final String WeekWed = 三 public static final String WeekThu = 四 public static final String WeekFri = 五 public static final String WeekSat = 六 private JPanel MainPanel;/日历面板 private JLabel yearsLabel;/“年份” 标签 private JSpinner yearsSpinner;/年份组合框 private JLabel monthsLabel;/“月份” 标签 private JComboB

6、ox monthsComboBox; /12月份下拉框 private JLabel InfoLabel;/信息显示标签 private JTable daysTable; /日表格 private AbstractTableModel daysModel;/天单元表格private Calendar calendar;/日历对象/*函数定义*/ public rili() /构造函数 MainPanel = (JPanel) getContentPane(); public void init() /初始化面板界面函数 MainPanel.setLayout(new BorderLayout

7、(); calendar = Calendar.getInstance(); /默认方式,以本地的时区和地区来构造Calendar yearsLabel = new JLabel(年 /设置年份标签显示 yearsSpinner = new JSpinner();/构造年份spinner组合框 yearsSpinner.setEditor(new JSpinner.NumberEditor(yearsSpinner, 0000); yearsSpinner.setValue(new Integer(calendar.get(Calendar.YEAR); yearsSpinner.addCha

8、ngeListener(new ChangeListener() /注册该组合框的事件监听器 public void stateChanged(ChangeEvent changeEvent) int day = calendar.get(Calendar.DAY_OF_MONTH); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.YEAR, (Integer) yearsSpinner.getValue().intValue(); int maxDay = calendar.getActualMaximum(Cal

9、endar.DAY_OF_MONTH); calendar.set(Calendar.DAY_OF_MONTH, day maxDay ? maxDay : day); updateView(); /更新显示 ); /- monthsComboBox = new JComboBox(); /月份下拉框 monthsLabel = new JLabel(月 /设置月份标签显示 for (int i = 1; i = 12; i+) /构造下拉框的12个月份 monthsComboBox.addItem(new Integer(i); monthsComboBox.setSelectedIndex

10、(calendar.get(Calendar.MONTH);/下拉框当前月份为选中状态 monthsComboBox.addActionListener(new ActionListener() /注册月份下拉框的事件监听器 public void actionPerformed(ActionEvent actionEvent) calendar.set(Calendar.MONTH, monthsComboBox.getSelectedIndex();/更新面板显示 ); InfoLabel=new JLabel(当前时区:中国标准时间 JPanel yearMonthPanel = new

11、 JPanel(); /定义年月面板 MainPanel.add(yearMonthPanel, BorderLayout.NORTH);/添加年月面板到日历面板的南面(最上方) MainPanel.add(InfoLabel, BorderLayout.SOUTH); yearMonthPanel.setLayout(new BorderLayout();/边布局模式 JPanel yearPanel = new JPanel(); /构建年份面板 yearMonthPanel.add(yearPanel, BorderLayout.WEST);/年份面板添加到年月面板西部(左边) year

12、Panel.setLayout(new BorderLayout();/设置年份面板为边布局并添加年份标签和组合框 yearPanel.add(yearsLabel, BorderLayout.EAST); yearPanel.add(yearsSpinner, BorderLayout.CENTER); /- JPanel monthPanel = new JPanel();/定义月份面板 yearMonthPanel.add(monthPanel, BorderLayout.EAST);/添加月份面板到年月面板的东面(右边) monthPanel.setLayout(new BorderL

13、ayout();/月份面板设为边布局方式 monthPanel.add(monthsLabel, BorderLayout.EAST);/添加月份名称标签到月份面板西面(左边) monthPanel.add(monthsComboBox, BorderLayout.CENTER);/添加月份下拉框到月份面板中间 JPanel txetPanel = new JPanel();/定义标题文本显示面板 yearMonthPanel.add(txetPanel,BorderLayout.CENTER);/添加标题文本显示面板到年月面板中间 daysModel = new AbstractTableM

14、odel() /设置7行7列 public int getRowCount() return 7; public int getColumnCount() public Object getValueAt(int row, int column) if (row = 0) /第一行显示星期 return getHeader(column); row-; Calendar calendar = (Calendar) rili.this.calendar.clone(); int dayCount = calendar.getActualMaximum(Calendar.DAY_OF_MONTH)

15、; int moreDayCount = calendar.get(Calendar.DAY_OF_WEEK) - 1; int index = row * 7 + column; int dayIndex = index - moreDayCount + 1; if (index dayCount) return null; else return new Integer(dayIndex); ; daysTable = new CalendarTable(daysModel, calendar); /构造日表格 daysTable.setCellSelectionEnabled(true)

16、;/设置表格单元格可选择 daysTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); daysTable.setDefaultRenderer(daysTable.getColumnClass(0), new TableCellRenderer() public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) String

17、 text = (value = null) ? : value.toString(); JLabel cell = new JLabel(text); cell.setOpaque(true); /绘制边界内的所有像素 if (row = 0) /第一行显示星期,设置为星期的前景色和背景色 cell.setForeground(headerForeground); cell.setBackground(headerBackground); else if (isSelected) /日期单元格如果选中,则设置为日期选中的前、背景色 cell.setForeground(selectedFor

18、eground); cell.setBackground(selectedBackground); else /设置日期单元格的普通前、背景色 cell.setForeground(foreground); cell.setBackground(background); return cell; MainPanel.add(daysTable, BorderLayout.CENTER);/添加日面板到日历面板中间/- public static String getHeader(int index) /设置第一行星期的显示 switch (index) case 0: return WeekS

19、un; case 1: return WeekMon; case 2: return WeekTue; case 3: return WeekWed; case 4: return WeekThu; case 5: return WeekFri; case 6: return WeekSat; default: public void updateView() /更新面板显示方法 daysModel.fireTableDataChanged();daysTable.setRowSelectionInterval(calendar.get(Calendar.WEEK_OF_MONTH), cal

20、endar.get(Calendar.WEEK_OF_MONTH);daysTable.setColumnSelectionInterval(calendar.get(Calendar.DAY_OF_WEEK) - 1,calendar.get(Calendar.DAY_OF_WEEK) - 1); public static class CalendarTable extends JTable /表格类 private Calendar calendar; public CalendarTable(TableModel model, Calendar calendar) /构造方法 supe

21、r(model); this.calendar = calendar; public void changeSelection(int row, int column, boolean toggle, boolean extend) /选择表格单元格时 super.changeSelection(row, column, toggle, extend); if (row = 0) /选择为第一行(星期)时不改变单元格 return; Object obj = getValueAt(row, column); if (obj != null) calendar.set(Calendar.DAY_

22、OF_MONTH, (Integer)obj).intValue();Clock.javaimport java.text.*;public class Clock extends JPanel implements Runnable private JLabel jl;private DateFormat df;public Clock() jl=new JLabel(); jl.setHorizontalAlignment(JLabel.CENTER); df=DateFormat.getDateTimeInstance(); new Thread(this).start(); this.

23、setLayout(new BorderLayout(); this.add(jl,BorderLayout.SOUTH); public void run() while(true) try Thread.sleep(1000); catch(InterruptedException ie) ie.printStackTrace(); jl.setText(df.format(new Date(); repaint();public void paintComponent(Graphics g) super.paintComponent(g); Calendar cal=Calendar.g

24、etInstance(); /得到当前的时间信息 int hour=cal.get(Calendar.HOUR); int minute=cal.get(Calendar.MINUTE); int second=cal.get(Calendar.SECOND); /得到当前的面板的大小信息 int width=this.getWidth(); int height=this.getHeight(); /钟的那个圆盘取两个之中小的那个 int small=widthheight?width:height; int diameter=(int)(small*0.8); int radius=dia

25、meter/2; /确定中心点 Point center=new Point(width/2,height/2); /确定时针,分钟,秒针的长度 int secondLength=(int)(radius*0.8); int minuteLength=(int)(secondLength*0.8); int hourLength=(int)(minuteLength*0.8); /确定时针,分针,秒针的另一端坐标 int secondX=center.x+(int)(secondLength*Math.sin(second*2*Math.PI/60.0); int secondY=center

26、.y-(int)(secondLength*Math.cos(second*2*Math.PI/60.0); int minuteX=center.x+(int)(minuteLength*Math.sin(minute*2*Math.PI/60.0); int minuteY=center.y-(int)(minuteLength*Math.cos(minute*2*Math.PI/60.0); int hourX=center.x+(int)(hourLength*Math.sin(minute/60.0+hour)*Math.PI/6.0); int hourY=center.y-(int)(hourLength*Math.cos(minute/60.0+hour)*Math.PI/6.0); Graphics2D g2d=(Graphics2D)g; /画表盘和刻度 g.drawOval(center.x-radius,center.y-radius,dia

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1