Drawing a Graph 3

From MyWiki
Jump to: navigation, search
import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*;
import java.sql.*;
 
public class Test1 extends JFrame  implements Runnable
 
{
 
Connection con = null;
Statement st = null;
ResultSet rs = null;
String url = "jdbc:mysql://argus.gold.ac.uk:3306/monitor_ad_response";
String user = "adresponse";
String password = "C1n0bbwT";
int oldPoint = 0;
int newPoint = 0;
int n = 10;
 
 
 
 
 
 
 
    public void paint(Graphics g) {
    	                          g.setColor(Color.WHITE);
 
    	                                                   //g.drawRect (n-1, 10+n-1 , 80, 50);
    	                                                  // for (int a=1;a<200;a++)
    	                                                              //           {
    	                                                               //          g.drawLine(1,a,500,a);
    	                                                               //          }
    	                          g.setColor(Color.BLACK);
 
    	                          //g.drawLine(n,oldPoint+50,n+1,newPoint+50);
    	                          g.drawOval(n,newPoint+30,5,5);
 
 
                                 // g.drawRect (n, 10+n , 80, 50); 
                                  }   	
 
	 public void run() {
                        System.out.println("Hello from a thread!");
 
 
                	                                     try{
    	                                     	             con = DriverManager.getConnection(url, user, password);
                                                             st = con.createStatement();
                                                              rs = st.executeQuery("select entered,server1 from response order by entered limit 30");
 
                                                               while (  rs.next())
                                                                                 {
                                                                                 int ii = rs.getInt("server1");
                                                                                 System.out.println("The result is " + ii);
                                                                                // oldPoint = newPoint;
                                                                                // newPoint = ii;
                                                                                oldPoint = 20;
                                                                                newPoint = 20;
                                                                                 n++;
                                                                                 n++;
                                                                                 n++;
                                                                                 n++;
                                                                                 n++;
                                                                                 n++;
                                                                                  n++;
                                                                                 n++;
                                                                                 n++;
 
                                                                                 repaint();
 
 
                                                                                 }
                                                                              }
 
                                                          catch(SQLException ex){ System.out.println(ex.toString());}
 
 
 
       // while(n < 100)
        //{
       // try{
       //     Thread.sleep(20);
        //   }
       // catch(Exception e){System.out.println(e.toString());}
       //  n++;
        //pressme.setText("asdf"+n);
 
      //  repaint();
       // }
    }
 
  JPanel pane = new JPanel();
 // JButton pressme = new JButton("Press Me");
  Test1()        // the frame constructor
  {
    super("JPrompt Demo"); setBounds(700,100,800,400);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container con = this.getContentPane(); // inherit main frame
    con.add(pane);    // JPanel containers default to FlowLayout
   // pressme.setMnemonic('P'); // associate hotkey to button
  //  pane.add(pressme); pressme.requestFocus();
    setVisible(true); // make frame visible
  }
  public static void main(String args[]) {
  	//new Test1();
   (new Thread(new Test1())).start();
  }
 
}