?? studentview.java
字號:
jComboBox1.setName("jComboBox1"); // NOI18N jTextField18.setText(resourceMap.getString("jTextField18.text")); // NOI18N jTextField18.setName("jTextField18"); // NOI18N javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane()); jDialog1.getContentPane().setLayout(jDialog1Layout); jDialog1Layout.setHorizontalGroup( jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jDialog1Layout.createSequentialGroup() .addGap(10, 10, 10) .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jDialog1Layout.createSequentialGroup() .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jDialog1Layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel3)) .addGroup(jDialog1Layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField18, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField17, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap()) ); jDialog1Layout.setVerticalGroup( jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jDialog1Layout.createSequentialGroup() .addContainerGap() .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(jTextField17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField18, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton3) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); setComponent(mainPanel); setMenuBar(menuBar); setStatusBar(statusPanel); }// </editor-fold>//GEN-END:initComponents private void helpMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpMenuActionPerformed // TODO add your handling code here: }//GEN-LAST:event_helpMenuActionPerformed private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed // TODO add your handling code here: if (jDialog2 == null) { JFrame mainFrame = StudentApp.getApplication().getMainFrame(); jDialog2 = new StudentAboutBox(mainFrame); jDialog2.setLocationRelativeTo(mainFrame); } StudentApp.getApplication().show(jDialog2); }//GEN-LAST:event_jMenuItem1ActionPerformed private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed if (jDialog3 == null) { JFrame mainFrame = StudentApp.getApplication().getMainFrame(); jDialog3 = new StudentAboutBox(mainFrame); jDialog3.setLocationRelativeTo(mainFrame); } StudentApp.getApplication().show(jDialog3); // TODO add your handling code here: }//GEN-LAST:event_jMenuItem2ActionPerformed private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed if (jDialog1 == null) { JFrame mainFrame = StudentApp.getApplication().getMainFrame(); jDialog1 = new StudentAboutBox(mainFrame); jDialog1.setLocationRelativeTo(mainFrame); } StudentApp.getApplication().show(jDialog1); // TODO add your handling code here: }//GEN-LAST:event_jMenuItem3ActionPerformedString id;String name;Float math,english,politics,algebra,probability,logic; private void jMenuItem12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem12ActionPerformed try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=denghan","sa",""); Statement stmt =con.createStatement(); ResultSet rs =stmt.executeQuery("select * from new"); DefaultTableModel jTableabc=(DefaultTableModel)jTable1.getModel(); while (rs.next()){ id=rs.getString("id"); name=rs.getString("name"); math=rs.getFloat("math"); english=rs.getFloat("English"); politics=rs.getFloat("politics"); algebra=rs.getFloat("algebra"); probability=rs.getFloat("probability"); logic=rs.getFloat("logic"); Object temp[]={id,name,math,english,politics,algebra,probability,logic}; jTableabc.addRow(temp); } rs.close(); stmt.close(); con.close(); }catch(Exception e){ e.printStackTrace(); } }//GEN-LAST:event_jMenuItem12ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed if(jTextField1.getText().equals("")){ JOptionPane.showMessageDialog(null,"學號不能為空"); }else if(jTextField2.getText().equals("")){ JOptionPane.showMessageDialog(null,"姓名不能為空"); }else if(jTextField3.getText().equals("")){ JOptionPane.showMessageDialog(null,"請填寫數學分析成績"); }else if(jTextField4.getText().equals("")){ JOptionPane.showMessageDialog(null,"請填寫大學英語成績"); }else if(jTextField5.getText().equals("")){ JOptionPane.showMessageDialog(null,"請填寫政治成績"); }else{ id=jTextField1.getText(); name=jTextField2.getText(); math=Float.parseFloat(jTextField3.getText()); english=Float.parseFloat(jTextField4.getText()); politics=Float.parseFloat(jTextField5.getText()); if(jTextField6.getText().equals("")){ algebra=(float)0; }else{ algebra=Float.parseFloat(jTextField6.getText()); } if(jTextField7.getText().equals("")){ probability=(float)0; }else{ probability=Float.parseFloat(jTextField7.getText()); } if(jTextField8.getText().equals("")){ logic=(float)0; }else{ logic=Float.parseFloat(jTextField8.getText()); } try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=denghan","sa",""); Statement stmt =con.createStatement(); ResultSet rs =stmt.executeQuery("select * from new where id = "+"'"+id+"'" ); if(rs.next()){ JOptionPane.showMessageDialog(null,"學號不能重復"); return; } } catch(Exception e){ e.printStackTrace(); } try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=denghan","sa",""); PreparedStatement stmt=null; stmt=con.prepareStatement( "INSERT INTO new VALUES(?,?,?,?,?,?,?,?)");//SQL語言 stmt.setString(1,id); stmt.setString(2,name); stmt.setFloat(3,math); stmt.setFloat(4,english); stmt.setFloat(5,politics); stmt.setFloat(6,algebra); stmt.setFloat(7,probability); stmt.setFloat(8,logic); DefaultTableModel jTableabc=(DefaultTableModel)jTable1.getModel(); Object temp[]={id,name,math,english,politics,algebra,probability,logic}; jTableabc.addRow(temp); stmt.executeUpdate();//提交SQL語言 stmt.clearParameters(); stmt.close(); stmt.close(); con.close(); } catch(Exception e){ e.printStackTrace(); } } }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed String temp=""; if(!(jTextField9.getText().equals(""))){ id=jTextField9.getText(); temp="id = "+id; } if(!(jTextField10.getText().equals(""))){ if(!(temp.equals(""))){ temp=temp+" AND"; } name=jTextField10.getText(); temp=temp+" name = "+"'"+name+"'"; } if(!(jTextField11.getText().equals(""))){ if(!(temp.equals(""))){ temp=temp+" AND"; } math=Float.parseFloat(jTextField11.getText()); temp=temp+" math = "+"'"+math+"'"; } if(!(jTextField12.getText().equals(""))){ if(!(temp.equals(""))){ temp=temp+" AND"; } english=Float.parseFloat(jTextField12.getText()); temp=temp+" English = "+"'"+english+"'"; } if(!(jTextField13.getText().equals(""))){ if(!(temp.equals(""))){ temp=temp+" AND"; } politics=Float.parseFloat(jTextField13.getText()); temp=temp+" politics = "+"'"+politics+"'"; } if(!(jTextField14.getText().equals(""))){ if(!(temp.equals(""))){ temp=temp+" AND"; } algebra=Float.parseFloat(jTextField14.getText()); temp=temp+" algebra = "+"'"+algebra+"'"; } if(!(jTextField15.getText().equals(""))){ if(!(temp.equals(""))){ temp=temp+" AND"; } probability=Float.parseFloat(jTextField15.getText()); temp=temp+" probability = "+"'"+probability+"'"; } if(!(jTextField16.getText().equals(""))){ if(!(temp.equals(""))){ temp=temp+" AND"; } logic=Float.parseFloat(jTextField16.getText()); temp=temp+" logic = "+"'"+logic+"'"; } DefaultTableModel jTableabc=(DefaultTableModel)jTable1.getModel(); jTableabc.setRowCount(0); try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=denghan","sa",""); Statement stmt = con.createStatement(); ResultSet rs =stmt.executeQuery("select * from new where "+temp ); while (rs.next()){ id=rs.getString("id"); name=rs.getString("name"); math=rs.getFloat("math"); english=rs.getFloat("English");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -