《ssd4实验五实验报告.doc》由会员分享,可在线阅读,更多相关《ssd4实验五实验报告.doc(5页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、实验五一、 实验目的 为进入时区编写一个接口程序二、 实验内容 将世界地图载入界面,通过下拉列表控件对时区进行选择,并在地图中显示,如下图(1)主界面(2)点击OK出现的界面三、 实验步骤1. 实验代码package mycode;import javax.swing.JOptionPane; * author Administratorpublic class exercise5 extends javax.swing.JFrame /* Creates new form exercise5 */ public exercise5() this.setResizable(false); in
2、itComponents(); this.setTitle(TIME/DATE);/设置标题 selectnum = -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 initComp
3、onents() jComboBox1 = new javax.swing.JComboBox(); jPanel1 = new javax.swing.JPanel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jCheckBox1 = new javax.swing.JCheckBox(); jLabel2 = new javax.swing.JLabel(); setDefaultCloseOperat
4、ion(javax.swing.WindowConstants.EXIT_ON_CLOSE); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String (GMT -12:00) Eniwetok, Kwajalein , (GMT -11:00) Midway Island, Samoa , (GMT -10:00) Hawaii , (GMT -09:00) Alaska , (GMT -08:00) Pacific Time (US and Canada); Tijuana , (GMT -07:00) Ari
5、zona , (GMT -07:00) Mountain Time (US and Canada) , (GMT -06:00) Central Time (US and Canada) , (GMT -06:00) Mexico City, Tegucigalpa , (GMT -06:00) Saskatchewan , (GMT -05:00) Bogota, Lima , (GMT -05:00) Eastern Time (US and Canada) , (GMT -05:00) Indiana (East) , (GMT -04:00) Atlantic Time (Canada
6、) , (GMT -04:00) Caracas, La Paz , (GMT -03:30) Newfoundland , (GMT -03:00) Brasilia , (GMT -03:00) Buenos Aires, Georgetown , (GMT -02:00) Mid-Atlantic , (GMT -01:00) Azores, Cape Verde Is. , (GMT +00:00) Greenwich Mean Time; Dublin, Edinburgh, London, Lisbon , (GMT +00:00) Monrovia, Casablanca , (
7、GMT +01:00) Berlin, Stockhold, Rome, Bern, Brussels, Vienna , (GMT +01:00) Paris, Madrid, Amsterdam , (GMT +01:00) Prage, Warsaw, Budapest , (GMT +02:00) Athens, Helsinki, Istanbul , (GMT +02:00) Cairo , (GMT +02:00) Eastern Europe , (GMT +02:00) Harare, Pretoria , (GMT +02:00) Israel , (GMT +03:00)
8、 Baghdad, Kuwait, Nairobi, Riyadh , (GMT +03:00) Moscow, St. Petersburgh, Kazan, Volgograd , (GMT +03:00) Tehran , (GMT +04:00) Abu Dhabi, Muscat, Tbilisi , (GMT +04:30) Kabul , (GMT +05:00) Islamabad, Karachi, Ekaterinburg, Tashkent , (GMT +05:30) Bombay, Calcutta, Madras, New Delhi, Colombo , (GMT
9、 +06:00) Almaty, Dhaka , (GMT +07:00) Bangkok, Jakarta, Hanoi , (GMT +08:00) Beijing, Chongqing, Urumqi , (GMT +08:00) Hong Kong, Perth, Singapore, Taipei , (GMT +09:00) Tokyo, Osaka, Sapporo, Seoul, Yakutsk , (GMT +09:30) Adelaide (GMT +09:30) Darwin , (GMT +10:00) Brisbane, Melbourne, Sydney , (GM
10、T +10:00) Guam, Port Moresby, Vladivostok , (GMT +10:00) Hobart , (GMT +11:00) Magadan, Solomon Is., New Caledonia , (GMT +12:00) Fiji, Kamchatka, Marshall Is. , (GMT +12:00) Wellington, Auckland ); jComboBox1.setBorder(javax.swing.BorderFactory.createCompoundBorder(); jComboBox1.addActionListener(n
11、ew java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jComboBox1ActionPerformed(evt); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParalle
12、lGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 9, Short.MAX_VALUE) jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 168, Short.MAX_VALUE) jButton1.setText(OK); jButton1.addActionListener(new java.awt.event.ActionLis
13、tener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton1ActionPerformed(evt); jButton2.setText(CANCEL); jButton3.setText(APPLY); jCheckBox1.setText(Automaticlly adjust clock for daynight saving changes); jCheckBox1.setEnabled(false); jCheckBox1.addActionListener(new java.awt.even
14、t.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jCheckBox1ActionPerformed(evt); jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource(/mycode/无标题.png); / NOI18N jLabel2.setText(jLabel2); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContent
15、Pane(); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.cr
16、eateSequentialGroup() .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 429, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.cre
17、ateSequentialGroup() .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap() .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(13, 13, 13) .addGroup(l
18、ayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(129, 129, 129) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jButton2, javax.swing.Gro
19、upLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(35, 35, 35) .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jCheckBox1, javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE) .addContainerGap(
20、) layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
21、 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComp
22、onent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 168, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jCheckBox1) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .
23、addComponent(jButton2) .addComponent(jButton3) .addContainerGap(66, Short.MAX_VALUE) pack(); / private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) selectnum = jComboBox1.getSelectedIndex(); selectstr = jComboBox1.getSelectedItem().toString(); for(int i=0;iselectnum;i+) jLabel2.set
24、Location(jLabel2.getLocation().x+20, jLabel2.getLocation().y); private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: String str = Time set to
25、n; str +=n; str +=Timezone=; str += selectstr; str +=noffset from GMT =; String str1 =String.format(%d, selectselectnum); str += str1; str +=n Auto daynight =Falsen; str +=; JOptionPane.showMessageDialog(null, str); * param args the command line arguments public static void main(String args) java.aw
26、t.EventQueue.invokeLater(new Runnable() public void run() new exercise5().setVisible(true); / Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JCheckBox jCheckBox1; private java
27、x.swing.JComboBox jComboBox1; private javax.swing.JLabel jLabel2; private javax.swing.JPanel jPanel1; / End of variables declaration private int selectnum; private String selectstr; private int select = -720, -660, -600, -540, -480, -420, -420 , -360, -360, -360, -300 ,-300 ,-300, -240 , -240, -210 ,-180, -180, -120, -060, +000, +000, +060, +060, +060, +120, +120, +120 , +120, +120, +180, +180, +180, +240, +270, +300, +330, +360, +420, +480, +480, +540, +570, +570, +600, +600, +600, +660, +720, +720 ;2. 实验截图四、 实验总结此次实验学会了使用java的复选框等控件,对java桌面编程加深了了解