《SSD4实验六实验报告.doc》由会员分享,可在线阅读,更多相关《SSD4实验六实验报告.doc(19页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、实验六一、 实验目的编写一个完整的DATE/TIME选择界面,能实现时间,时区选择对windows显示属性界面进行分析,写出UAR报告二、 实验内容编写以下程序项目,并包含以下内容要求: The second setting (0 to 59) The minute setting (0 to 59) The hour setting (in 24 hour time, 0 to 23) The day of the month The month of the year The year The index of the currently selected time zone The of
2、fset in minutes from GMT for the currently-selected time zone The title of the currently selected time zone 样例界面:对以下界面进行界面分析三、 实验步骤实验代码 * To change this template, choose Tools | Templates * and open the template in the editor. * exercise5B.java * Created on 2012-12-2, 16:13:25package mycode;import j
3、ava.awt.BasicStroke;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Component;import java.awt.Graphics;import java.awt.Graphics2D;import java.util.Calendar;import java.util.GregorianCalendar;import java.util.TimerTask;import javax.swing.ButtonGroup;import javax.swing.JLabel;import
4、 javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JSpinner;import javax.swing.JTable;import javax.swing.SpinnerNumberModel;import javax.swing.table.AbstractTableModel;import javax.swing.table.TableCellRenderer; / Variables declaration - do not modify / Variables declaration - do
5、not modify * author Administratorpublic class exercise5B extends javax.swing.JFrame /* Creates new form exercise5B */ public exercise5B() calendar = Calendar.getInstance(); amorpm = calendar.get(Calendar.AM_PM);/获取当天是在上午还是下午 initComponents(); x=jLabel1.getLocation().x; y=jLabel1.getLocation().y; sel
6、ectnum = -1; /* This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. SuppressWarnings(unchecked) / private void initComponents() jButton1 = new javax.swing.JButton(); jBu
7、tton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); jTabbedPane1 = new javax.swing.JTabbedPane(); jPanel1 = new javax.swing.JPanel(); jPanel4 = new javax.swing.JPanel(); jSpinner1 = new javax.swing.JSpinner(); jScrollPane1 = new javax.swing.JS
8、crollPane(); jTable1 = new javax.swing.JTable(); jComboBox2 = new javax.swing.JComboBox(); jPanel5 = new javax.swing.JPanel(); jSpinner2 = new JSpinner(new SpinnerNumberModel(1,1,12,1); jSpinner3 = new JSpinner(new SpinnerNumberModel(1,0,59,1); jSpinner4 = new JSpinner(new SpinnerNumberModel(1,0,59,
9、1); jRadioButton1 = new javax.swing.JRadioButton(); jRadioButton2 = new javax.swing.JRadioButton(); jPanel6 = new javax.swing.JPanel(); jLabel2 = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jComboBox1 = new javax.swing.JComboBox(); jPanel3 = new javax.swing.JPanel(); jLabel1 = new
10、javax.swing.JLabel(); jCheckBox1 = new javax.swing.JCheckBox(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle(TIME/DATE); jButton1.setBackground(new java.awt.Color(153, 153, 153); jButton1.setFont(new java.awt.Font(宋体, 0, 14); jButton1.setText(ok); jButton1.setBorder(
11、javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED); jButton1.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton1ActionPerformed(evt); jButton2.setBackground(new java.awt.Color(153, 153, 153); jButt
12、on2.setFont(new java.awt.Font(宋体, 0, 14); jButton2.setText(cancel); jButton2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED); jButton2.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButto
13、n2ActionPerformed(evt); jButton3.setBackground(new java.awt.Color(153, 153, 153); jButton3.setFont(new java.awt.Font(宋体, 0, 14); / NOI18N jButton3.setText(apply); jButton3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED); jButton3.addActionListener(new jav
14、a.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton3ActionPerformed(evt); jLabel3.setFont(new java.awt.Font(宋体, 0, 14); jLabel3.setText(Ponze Exampe); jTabbedPane1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED
15、, null, java.awt.Color.darkGray, null, null); jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(Date&Time); jPanel4.setFont(new java.awt.Font(宋体, 0, 14); jSpinner1.setEditor(new JSpinner.NumberEditor(jSpinner1, 0000); jSpinner1.setValue(new Integer(calendar.get(Calendar.YEAR); jSpinner1
16、.addChangeListener(new javax.swing.event.ChangeListener() public void stateChanged(javax.swing.event.ChangeEvent evt) jSpinner1StateChanged(evt); jScrollPane1.setPreferredSize(new java.awt.Dimension(45, 40); daysModel =new AbstractTableModel() public int getRowCount() return 6; public int getColumnC
17、ount() return 7; public String getColumnName(int col) switch (col) case 0: return WEEK_SUN; case 1: return WEEK_MON; case 2: return WEEK_TUE; case 3: return WEEK_WED; case 4: return WEEK_THU; case 5: return WEEK_FRI; case 6: return WEEK_SAT; default: return null; /设置日期在哪显示 public Object getValueAt(i
18、nt row, int column) / row-; Calendar calendar = (Calendar) exercise5B.this.calendar.clone(); calendar.set(Calendar.DAY_OF_MONTH, 1); int dayCount = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); int moreDayCount = calendar.get(Calendar.DAY_OF_WEEK) - 1; int index = row * 7 + column; int dayIndex
19、= index - moreDayCount + 1; if (index dayCount) return null; else return new Integer(dayIndex); jTable1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0); jTable1.setModel(daysModel); jTable1.setCellSelectionEnabled(true); jTable1.setShowHorizontalLines(false); jTable1
20、.setShowVerticalLines(false); jTable1.setDefaultRenderer(jTable1.getColumnClass(0), new TableCellRenderer() public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) String text = (value = null) ? : value.toString(); daystr
21、=text;/获取选择的日期 JLabel cell = new JLabel(text); cell.setOpaque(true); if (row = -1) cell.setForeground(headerForeground); cell.setBackground(headerBackground); else if (isSelected) cell.setForeground(selectedForeground); cell.setBackground(selectedBackground); else cell.setForeground(foreground); cel
22、l.setBackground(background); return cell; jScrollPane1.setViewportView(jTable1); jComboBox2.setEditable(true); jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String January , February , Marcy , April , May , June , July , August , September , October , November , December , ); jComboBo
23、x2.setSelectedIndex(calendar.get(Calendar.MONTH); jComboBox2.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jComboBox2ActionPerformed(evt); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayo
24、ut(jPanel4Layout); jPanel4Layout.setHorizontalGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jS
25、crollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE) .addGroup(jPanel4Layout.createSequentialGroup() .addComponent(jComboBox2, 0, 117, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(
26、jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap() jPanel4Layout.setVerticalGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup() .addContainerGap() .addGroup(
27、jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swi
28、ng.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(42, Short.MAX_VALUE) jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Time, javax.swing.border.Titl
29、edBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font(宋体, 0, 14); / NOI18N jPanel5.setPreferredSize(new java.awt.Dimension(231, 231); jSpinner2.setEditor(new JSpinner.NumberEditor(jSpinner2, 00); if(amorpm=Calendar.AM) jSpinner2.setValue(new Integer(cale
30、ndar.get(Calendar.HOUR); else jSpinner2.setValue(new Integer(calendar.get(Calendar.HOUR); jSpinner2.addChangeListener(new javax.swing.event.ChangeListener() public void stateChanged(javax.swing.event.ChangeEvent evt) jSpinner2StateChanged(evt); jSpinner3.setEditor(new JSpinner.NumberEditor(jSpinner3
31、, 00); jSpinner3.setValue(new Integer(calendar.get(Calendar.MINUTE); jSpinner4.setEditor(new JSpinner.NumberEditor(jSpinner4, 00); jSpinner4.setValue(new Integer(calendar.get(Calendar.SECOND); jRadioButton1.setText(AM); group.add(jRadioButton1); jRadioButton2.setText(PM); group.add(jRadioButton2); j
32、Panel6.setLayout(new java.awt.GridLayout(1, 0); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout.setHorizontalGroup( jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.creat
33、eSequentialGroup() .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup() .addContainerGap() .addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(j
34、avax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jSpinner3, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(14, 14, 14) .addComponent(jSpinner4, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(1
35、8, 18, 18) .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jRadioButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jRadioButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.Grou
36、pLayout.PREFERRED_SIZE) .addGroup(jPanel5Layout.createSequentialGroup() .addGap(30, 30, 30) .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(18, Short.MAX_VALUE) jPanel5Layout.setVerticalGroup( jPanel5Layout.createParallelGr
37、oup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE) .addGap(18, 18, 18) .addGroup(jPanel5Layout.createParallelG
38、roup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(jPanel5Layout.createSequentialGroup() .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jSpinner3, javax.swing.GroupL