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. */ package frames; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PiePlot; import org.jfree.chart.plot.PiePlot3D; import org.jfree.data.general.DefaultPieDataset; /** * * @author akshara,pooja,ravi */ public class Screen2 extends javax.swing.JFrame { /** * Creates new form screen */ public Screen2() { initComponents(); showDate(); //showTime(); } /** * 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() { jPanel1 = new javax.swing.JPanel(); Exit = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); DateTF = new javax.swing.JTextField(); Piechart = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setBackground(new java.awt.Color(153, 0, 153)); jPanel1.setBackground(new java.awt.Color(22, 110, 22)); Exit.setBackground(new java.awt.Color(255, 0, 0)); Exit.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N Exit.setForeground(new java.awt.Color(255, 255, 255)); Exit.setText("Exit"); Exit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ExitActionPerformed(evt); } }); jTable1.setBackground(java.awt.Color.lightGray); jTable1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(51, 0, 0), 2)); jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { "process1", new Long(9729719), new Integer(267839), "TCP", "Listen" }, { "process2", new Long(5930022), new Integer(356118), "TCP", "Established" }, { "process3", new Long(12648669), new Integer(154132), "TCP", "Listen" }, { "process4", new Long(2806211), new Integer(131547), "UDP", "Time_Wait" } }, new String[] { "Process", "MemoryInfo", "IoInfo", "Protocol", "State" }) { Class[] types = new Class[] { java.lang.String.class, java.lang.Long.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } }); jTable1.setGridColor(new java.awt.Color(51, 0, 0)); jScrollPane1.setViewportView(jTable1); jLabel1.setBackground(new java.awt.Color(255, 51, 0)); jLabel1.setFont(new java.awt.Font("Monotype Corsiva", 3, 36)); // NOI18N jLabel1.setForeground(java.awt.Color.white); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText("Metrics Collector"); jLabel2.setBackground(new java.awt.Color(255, 255, 51)); jLabel2.setForeground(new java.awt.Color(157, 255, 101)); jLabel2.setText("Date"); DateTF.setEditable(false); DateTF.setBackground(new java.awt.Color(255, 153, 153)); DateTF.setFont(new java.awt.Font("Tahoma", 3, 10)); // NOI18N DateTF.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { DateTFActionPerformed(evt); } }); Piechart.setBackground(new java.awt.Color(204, 0, 51)); Piechart.setFont(new java.awt.Font("Tahoma", 1, 8)); // NOI18N Piechart.setForeground(new java.awt.Color(204, 255, 255)); Piechart.setText("Piechart"); Piechart.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PiechartActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(143, 143, 143).addComponent( jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel1Layout.createSequentialGroup().addGap(101, 101, 101).addComponent( jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(118, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup().addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(DateTF, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(23, 23, 23)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addComponent(Exit, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(44, 44, 44)))) .addGroup(jPanel1Layout.createSequentialGroup().addGap(251, 251, 251).addComponent(Piechart) .addGap(0, 0, Short.MAX_VALUE))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addGap(19, 19, 19) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(DateTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE) .addComponent(jLabel1).addGap(18, 18, 18) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(73, 73, 73).addComponent(Piechart).addGap(67, 67, 67).addComponent(Exit, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(19, 19, 19))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent( jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); pack(); }// </editor-fold>//GEN-END:initComponents private void ExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExitActionPerformed jLabel1.setText("Metrics Collector"); System.exit(0); }//GEN-LAST:event_ExitActionPerformed private void DateTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DateTFActionPerformed // TODO add your handling code here: }//GEN-LAST:event_DateTFActionPerformed private void PiechartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PiechartActionPerformed DefaultPieDataset piedataset = new DefaultPieDataset(); piedataset.setValue("Process one", new Integer(10)); piedataset.setValue("Process two", new Integer(20)); piedataset.setValue("Process three", new Integer(30)); piedataset.setValue("Process four", new Integer(40)); JFreeChart chart = ChartFactory.createPieChart("Piechart", piedataset, true, true, true); PiePlot P = (PiePlot) chart.getPlot(); //P.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame frame = new ChartFrame("piechart", chart); frame.setVisible(true); frame.setSize(450, 500); }//GEN-LAST:event_PiechartActionPerformed /** * @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; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Screen2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Screen2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Screen2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Screen2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Screen2().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField DateTF; private javax.swing.JButton Exit; private javax.swing.JButton Piechart; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable jTable1; // End of variables declaration//GEN-END:variables void showDate() { Date d = new Date(); SimpleDateFormat s = new SimpleDateFormat("yy-MM-dd"); DateTF.setText(s.format(d)); } }