Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author n9420924 */ import java.util.*; import javax.mail.*; import java.awt.Color; import java.awt.Desktop; import java.io.File; import java.sql.*; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import javax.swing.*; import net.proteanit.sql.DbUtils; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.ChartRenderingInfo; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.entity.StandardEntityCollection; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PiePlot3D; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.renderer.category.BarRenderer; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.jdbc.JDBCCategoryDataset; public class UserInfo_Frame extends javax.swing.JFrame { Connection conn = null; ResultSet rs = null; PreparedStatement pst = null; /** * Creates new form UserInfo_Frame */ public UserInfo_Frame() { initComponents(); conn = javaconnect.ConnectDB(); update_table(); } private void update_table() { String sql = "select * from UserInfo"; try { pst = conn.prepareStatement(sql); rs = pst.executeQuery(); Table_UserInfo.setModel(DbUtils.resultSetToTableModel(rs)); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex); } finally { try { rs.close(); pst.close(); //conn.close(); } catch (Exception e) { } } } /** * 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") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jToolBar1 = new javax.swing.JToolBar(); jTabbedPane4 = new javax.swing.JTabbedPane(); jPanel9 = new javax.swing.JPanel(); Combo_parameter = new javax.swing.JComboBox(); jLabel13 = new javax.swing.JLabel(); Min = new javax.swing.JTextField(); Max = new javax.swing.JTextField(); jButton5 = new javax.swing.JButton(); jPanel10 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jTextField3 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jTabbedPane5 = new javax.swing.JTabbedPane(); jDesktopPane1 = new javax.swing.JDesktopPane(); jScrollPane1 = new javax.swing.JScrollPane(); Table_UserInfo = new javax.swing.JTable(); jPanel1 = new javax.swing.JPanel(); jLabel6 = new javax.swing.JLabel(); txt_pumid = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); txt_temperature = new javax.swing.JTextField(); txt_pressure = new javax.swing.JTextField(); txt_volume = new javax.swing.JTextField(); jLabel12 = new javax.swing.JLabel(); txt_rotationalSpd = new javax.swing.JTextField(); jButton4 = new javax.swing.JButton(); txt_date = new com.toedter.calendar.JDateChooser(); jButton7 = new javax.swing.JButton(); barChart_btn = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); jSlider1 = new javax.swing.JSlider(); txt_valueInt = new javax.swing.JTextField(); jButton2 = new javax.swing.JButton(); df = new com.toedter.calendar.JDateChooser(); jProgressBar1 = new javax.swing.JProgressBar(); jButton3 = new javax.swing.JButton(); jPanel3 = new javax.swing.JPanel(); jButton8 = new javax.swing.JButton(); jScrollPane2 = new javax.swing.JScrollPane(); jTree1 = new javax.swing.JTree(); btn_openFile = new javax.swing.JButton(); jLabel11 = new javax.swing.JLabel(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenu2 = new javax.swing.JMenu(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jToolBar1.setRollover(true); Combo_parameter.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "Pressure", "VolumeFlow", "Tempearature", "RotationalSpeed", "Torque" })); jLabel13.setText("Value"); jButton5.setText("OK"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9); jPanel9.setLayout(jPanel9Layout); jPanel9Layout.setHorizontalGroup(jPanel9Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel9Layout.createSequentialGroup() .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel9Layout.createSequentialGroup().addGap(26, 26, 26) .addComponent(jLabel13).addGap(18, 18, 18) .addComponent(Min, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(Max, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel9Layout.createSequentialGroup().addGap(135, 135, 135).addComponent( Combo_parameter, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel9Layout.createSequentialGroup().addGap(173, 173, 173).addComponent( jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(708, Short.MAX_VALUE))); jPanel9Layout.setVerticalGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel9Layout.createSequentialGroup().addContainerGap() .addComponent(Combo_parameter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(20, 20, 20) .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel13) .addComponent(Min, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(Max, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18).addComponent(jButton5).addContainerGap(393, Short.MAX_VALUE))); jTabbedPane4.addTab("User Input", jPanel9); jLabel1.setText("PARAMETER"); jLabel2.setText("MIN"); jLabel3.setText("MAX"); jLabel4.setText("AVG"); jLabel5.setText("Presure"); jButton1.setText("Calculate"); javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10); jPanel10.setLayout(jPanel10Layout); jPanel10Layout.setHorizontalGroup(jPanel10Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel10Layout.createSequentialGroup().addGroup(jPanel10Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel10Layout.createSequentialGroup().addGap(38, 38, 38).addGroup(jPanel10Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel10Layout.createSequentialGroup().addComponent(jLabel1) .addGap(54, 54, 54).addComponent(jLabel2)) .addComponent(jLabel5)) .addGroup(jPanel10Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel10Layout.createSequentialGroup().addGap(85, 85, 85) .addComponent(jLabel3).addGap(91, 91, 91).addComponent(jLabel4)) .addGroup(jPanel10Layout.createSequentialGroup().addGap(66, 66, 66) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(49, 49, 49).addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGroup(jPanel10Layout.createSequentialGroup().addGap(255, 255, 255) .addComponent(jButton1))) .addContainerGap(583, Short.MAX_VALUE)) .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel10Layout.createSequentialGroup().addGap(160, 160, 160) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(833, Short.MAX_VALUE)))); jPanel10Layout.setVerticalGroup(jPanel10Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel10Layout.createSequentialGroup().addGap(30, 30, 30) .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1).addComponent(jLabel2).addComponent(jLabel3) .addComponent(jLabel4)) .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel10Layout.createSequentialGroup().addGap(18, 18, 18) .addComponent(jLabel5)) .addGroup(jPanel10Layout.createSequentialGroup().addGap(27, 27, 27) .addGroup(jPanel10Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 359, Short.MAX_VALUE) .addComponent(jButton1).addGap(37, 37, 37)) .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel10Layout.createSequentialGroup().addGap(78, 78, 78) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(424, Short.MAX_VALUE)))); jTabbedPane4.addTab("Statistics values", jPanel10); jDesktopPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Table UserInfo", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 16), new java.awt.Color(51, 0, 51))); // NOI18N Table_UserInfo .setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null } }, new String[] { "Title 1", "Title 2", "Title 3", "Title 4" })); Table_UserInfo.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { Table_UserInfoMouseClicked(evt); } }); jScrollPane1.setViewportView(Table_UserInfo); jLabel6.setText("PumId"); jLabel7.setText("Date"); jLabel8.setText("Pressure"); jLabel9.setText("Temperature"); jLabel10.setText("Volume Flow"); jLabel12.setText("Rotational Spd"); jButton4.setText("Save"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); txt_date.setDateFormatString("yyyy-MM-dd"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(28, 28, 28).addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel9).addComponent(jLabel8).addComponent(jLabel7) .addComponent(jLabel6)) .addComponent(jLabel10).addComponent(jLabel12)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(txt_pumid) .addComponent(txt_pressure, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE) .addComponent(txt_temperature, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE) .addComponent(txt_volume, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE) .addComponent(txt_rotationalSpd, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE) .addComponent(txt_date, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(46, 46, 46)) .addGroup(jPanel1Layout.createSequentialGroup().addGap(148, 148, 148).addComponent(jButton4) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6).addComponent(txt_pumid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel7).addComponent(txt_date, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8).addComponent(txt_pressure, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel9).addComponent(txt_temperature, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel10).addComponent(txt_volume, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel12).addComponent(txt_rotationalSpd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton4) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jButton7.setText("Pie Chart"); jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt); } }); barChart_btn.setText("Bar Chart"); barChart_btn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { barChart_btnActionPerformed(evt); } }); jButton6.setText("Query Chart"); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt); } }); javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1); jDesktopPane1.setLayout(jDesktopPane1Layout); jDesktopPane1Layout.setHorizontalGroup(jDesktopPane1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDesktopPane1Layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 199, Short.MAX_VALUE) .addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jDesktopPane1Layout.createSequentialGroup().addComponent(jButton7) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(barChart_btn).addGap(27, 27, 27).addComponent(jButton6)) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 390, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(32, 32, 32))); jDesktopPane1Layout.setVerticalGroup(jDesktopPane1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jDesktopPane1Layout.createSequentialGroup().addGap(40, 40, 40) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(jDesktopPane1Layout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(31, 31, 31) .addGroup( jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton7).addComponent(barChart_btn).addComponent(jButton6)) .addGap(0, 67, Short.MAX_VALUE))); jDesktopPane1.setLayer(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER); jDesktopPane1.setLayer(jPanel1, javax.swing.JLayeredPane.DEFAULT_LAYER); jDesktopPane1.setLayer(jButton7, javax.swing.JLayeredPane.DEFAULT_LAYER); jDesktopPane1.setLayer(barChart_btn, javax.swing.JLayeredPane.DEFAULT_LAYER); jDesktopPane1.setLayer(jButton6, javax.swing.JLayeredPane.DEFAULT_LAYER); jTabbedPane5.addTab("tab1", jDesktopPane1); jTabbedPane4.addTab("Decision Making", jTabbedPane5); jSlider1.setMajorTickSpacing(20); jSlider1.setMaximum(120); jSlider1.setMinorTickSpacing(5); jSlider1.setPaintLabels(true); jSlider1.setPaintTicks(true); jButton2.setText("OK"); jProgressBar1.setStringPainted(true); jButton3.setText("Progress OK"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addContainerGap(715, Short.MAX_VALUE) .addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout .createSequentialGroup().addGap(79, 79, 79).addGroup(jPanel2Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(df, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addComponent(jButton3).addGap(35, 35, 35))) .addGap(35, 35, 35)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(txt_valueInt, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(57, 57, 57).addComponent(jButton2)) .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(93, 93, 93))); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGap(64, 64, 64) .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(26, 26, 26) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txt_valueInt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton2)) .addGap(18, 18, 18) .addComponent(df, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(8, 8, 8) .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(jButton3).addContainerGap(217, Short.MAX_VALUE))); jTabbedPane4.addTab("tab4", jPanel2); jButton8.setText("Mail"); jButton8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton8ActionPerformed(evt); } }); jTree1.setModel(new FileSystemModel(new File("C:\\Users"))); jTree1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jTree1MouseClicked(evt); } }); jScrollPane2.setViewportView(jTree1); btn_openFile.setText("open File"); btn_openFile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btn_openFileActionPerformed(evt); } }); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout .setHorizontalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btn_openFile).addGap(171, 171, 171).addComponent(jButton8) .addContainerGap(498, Short.MAX_VALUE))); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addGap(31, 31, 31) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton8).addComponent(btn_openFile)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 468, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 60, Short.MAX_VALUE))); jTabbedPane4.addTab("tab5", jPanel3); jLabel11.setText("jLabel11"); jMenu1.setText("File"); jMenuBar1.add(jMenu1); jMenu2.setText("Edit"); jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(623, 623, 623).addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addGap(31, 31, 31).addComponent(jLabel11) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addComponent(jTabbedPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 1081, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(71, 71, 71) .addComponent(jTabbedPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 562, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(86, 86, 86).addComponent(jLabel11) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); setSize(new java.awt.Dimension(1130, 735)); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed int value = Integer.parseInt(txt_valueInt.getText()); jProgressBar1.setValue(value); }//GEN-LAST:event_jButton3ActionPerformed private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed String val1 = Min.getText(); String val2 = Max.getText(); String tmp = Combo_parameter.getSelectedItem().toString(); if (tmp == "Pressure") { try { String sql = "select * from UserInfo where pressure between '" + val1 + "' and '" + val2 + "' "; System.out.println(sql); pst = conn.prepareStatement(sql); rs = pst.executeQuery(); Table_UserInfo.setModel(DbUtils.resultSetToTableModel(rs)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } else if (tmp == "VolumeFlow") { try { String sql = "select * from UserInfo where volume between '" + val1 + "'and '" + val2 + "' "; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); Table_UserInfo.setModel(DbUtils.resultSetToTableModel(rs)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } }//GEN-LAST:event_jButton5ActionPerformed private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed try { String sql = "insert into UserInfo (Pumpid,Date,pressure,temperature,volume,roatitionalSpeed) values (?,?,?,?,?,?)"; pst = conn.prepareStatement(sql); pst.setString(1, txt_pumid.getText()); pst.setString(2, ((JTextField) txt_date.getDateEditor().getUiComponent()).getText()); pst.setString(3, txt_pressure.getText()); pst.setString(4, txt_temperature.getText()); pst.setString(5, txt_volume.getText()); pst.setString(6, txt_rotationalSpd.getText()); pst.execute(); JOptionPane.showMessageDialog(null, "Saved"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } update_table(); }//GEN-LAST:event_jButton4ActionPerformed private void Table_UserInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Table_UserInfoMouseClicked try { int row = Table_UserInfo.getSelectedRow(); String Table_click = (Table_UserInfo.getModel().getValueAt(row, 0).toString()); //System.out.println("Table_Click is: " + Table_click); String sql = "select * from UserInfo where Pumpid='" + Table_click + "'"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); if (rs.next()) { String pumpID = rs.getString("Pumpid"); String inputDate = rs.getString("Date"); String pressure = rs.getString("pressure"); String tempt = rs.getString("temperature"); String vol = rs.getString("volume"); String roatitional = rs.getString("roatitionalSpeed"); txt_pumid.setText(pumpID); ((JTextField) txt_date.getDateEditor().getUiComponent()).setText(inputDate); // txt_date.setDate(inputDate); txt_pressure.setText(pressure); txt_temperature.setText(tempt); txt_volume.setText(vol); txt_rotationalSpd.setText(roatitional); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }//GEN-LAST:event_Table_UserInfoMouseClicked private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed String pressure = txt_pressure.getText(); String temperature = txt_temperature.getText(); String volumeflow = txt_volume.getText(); String rotationalSpeed = txt_rotationalSpd.getText(); DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("Pressure", new Double(pressure)); pieDataset.setValue("Temperature", new Double(temperature)); pieDataset.setValue("Volume Flow", new Double(volumeflow)); pieDataset.setValue("Rotational Speeed", new Double(rotationalSpeed)); //JFreeChart chart = ChartFactory.createPieChart("Pie Chart",pieDataset,true,true,true); // create normal piechart //PiePlot3D p = (PiePlot)chart.getPlot(); JFreeChart chart = ChartFactory.createPieChart3D("Parameter Pie Chart", pieDataset, true, true, true);// create 3D piechart PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame cframe = new ChartFrame("Pie Chart", chart); cframe.setVisible(true); cframe.setSize(450, 500); try { //save chart as PNG final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("chart.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (Exception e) { } }//GEN-LAST:event_jButton7ActionPerformed private void barChart_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_barChart_btnActionPerformed //create dataset values DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(80, "Marks", "Student1"); dataset.setValue(50, "Marks", "Student2"); dataset.setValue(75, "Marks", "Student3"); dataset.setValue(95, "Marks", "Student4"); //create bar chart JFreeChart chart = ChartFactory.createBarChart("Student Score", "Student Name", "Marks", dataset, PlotOrientation.VERTICAL, false, true, true); // create Line chart FreeChart chart = ChartFactory.createLineChart("Student Score", "Student Name", "Marks", dataset,PlotOrientation.VERTICAL,false,true,true); // set properties chart.setBackgroundPaint(Color.YELLOW);// change background color to yellow chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartFrame bframe = new ChartFrame("Bar Chart for student", chart); bframe.setVisible(true); bframe.setSize(450, 350); }//GEN-LAST:event_barChart_btnActionPerformed private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed try { String query = "select date,pressure from UserInfo"; JDBCCategoryDataset dataset = new JDBCCategoryDataset(javaconnect.ConnectDB(), query); JFreeChart chart = ChartFactory.createLineChart("Query Chart", "Date", "Pressure", dataset, PlotOrientation.VERTICAL, false, true, true); BarRenderer renderer = null; CategoryPlot plot = null; renderer = new BarRenderer(); ChartFrame frame = new ChartFrame("Query Chart", chart); frame.setVisible(true); frame.setSize(400, 650); } catch (Exception e) { } }//GEN-LAST:event_jButton6ActionPerformed private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed Properties props = new Properties(); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.socketFactory.port ", "465"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("anhduc.nguyen77000@gmail.com", "Matmachung020587"); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("anhduc.nguyen77000@gmail.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("oracle.submit@gmail.com")); message.setSubject("hi this is me"); message.setText("hi how are you, i am fine"); Transport.send(message); JOptionPane.showMessageDialog(null, "message sent"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }//GEN-LAST:event_jButton8ActionPerformed private void jTree1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTree1MouseClicked Jtreevar = jTree1.getSelectionPath().toString().replaceAll("[\\[\\]]", "").replace(", ", "\\"); }//GEN-LAST:event_jTree1MouseClicked private void btn_openFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_openFileActionPerformed try { File Selection = new File(Jtreevar); if (Selection.exists()) { if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(Selection); } else { JOptionPane.showMessageDialog(this, "Awt Desktop is not supported", "Error", JOptionPane.INFORMATION_MESSAGE); } } else { JOptionPane.showMessageDialog(this, "File does not exist", "Error", JOptionPane.INFORMATION_MESSAGE); } } catch (Exception e) { e.printStackTrace(); } }//GEN-LAST:event_btn_openFileActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { /* if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; }*/ // select Look and Feel of Jtattoo UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel"); } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(UserInfo_Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(UserInfo_Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(UserInfo_Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(UserInfo_Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new UserInfo_Frame().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox Combo_parameter; private javax.swing.JTextField Max; private javax.swing.JTextField Min; private javax.swing.JTable Table_UserInfo; private javax.swing.JButton barChart_btn; private javax.swing.JButton btn_openFile; private com.toedter.calendar.JDateChooser df; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JButton jButton6; private javax.swing.JButton jButton7; private javax.swing.JButton jButton8; private javax.swing.JDesktopPane jDesktopPane1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel10; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel9; private javax.swing.JProgressBar jProgressBar1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JSlider jSlider1; private javax.swing.JTabbedPane jTabbedPane4; private javax.swing.JTabbedPane jTabbedPane5; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JToolBar jToolBar1; private javax.swing.JTree jTree1; private com.toedter.calendar.JDateChooser txt_date; private javax.swing.JTextField txt_pressure; private javax.swing.JTextField txt_pumid; private javax.swing.JTextField txt_rotationalSpd; private javax.swing.JTextField txt_temperature; private javax.swing.JTextField txt_valueInt; private javax.swing.JTextField txt_volume; // End of variables declaration//GEN-END:variables String time; String Jtreevar; }