Académique Documents
Professionnel Documents
Culture Documents
*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.text.*;
import javax.swing.*;
import java.sql.*;
import java.io.*;
class Login extends JFrame implements ActionListener
{
JButton SUBMIT;
JPanel panel;
JLabel label1,label2;
final JTextField text1,text2;
Login()
{
label1 = new JLabel();
label1.setText("Username:");
text1 = new JTextField(15);
label2 = new JLabel();
label2.setText("Password:");
text2 = new JPasswordField(15);
SUBMIT=new JButton("SUBMIT");
panel=new JPanel(new GridLayout(3,1));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(SUBMIT);
add(panel,BorderLayout.CENTER);
SUBMIT.addActionListener(this);
setTitle("LOGIN FORM");
}
public void actionPerformed(ActionEvent ae)
{
int i;
String value1=text1.getText();
String value2=text2.getText();
if (value1.equals("admin") && value2.equals("torres")) {
NextPage page=new NextPage();
page.setVisible(true);
JLabel label = new JLabel("WELCOME TO SURVEY MANAGEMENT SYSTEM");
page.getContentPane().add(label);
abd=new JButton("Download");
abu=new JButton("Update");
abv=new JButton("View");
setBackground(Color.green);
setLayout(null);
//PImage ai = new PImage();
add(ag1);
add(ag2);
add(ag3);
add(agt1);
add(agt2);
add(agt3);
add(abu);
add(abv);
add(abd);
abd.addActionListener(this);
abu.addActionListener(this);
abv.addActionListener(this);
ag1.setBounds(100,100,300,25);
ag2.setBounds(100,200,300,25);
ag3.setBounds(100,300,300,25);
agt1.setBounds(420,100,100,25);
agt2.setBounds(420,200,100,25);
agt3.setBounds(420,300,100,25);
abu.setBounds(75,450,150,30);
abv.setBounds(300,450,150,30);
abd.setBounds(500,450,150,30);
try
{
String str1="update agri set amount="+i+
" where crop='Rice';";
r= stmt.executeUpdate(str1);
String str2="update agri set amount="+j+
" where crop='Wheat';";
r= stmt.executeUpdate(str2);
String str3="update agri set amount="+k+
" where crop='Barley';";
r= stmt.executeUpdate(str3);
JOptionPane.showMessageDialog(this,"UPDA
TE SUCCESSFULL!!",
"SUCCESS",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception e)
{
}
}
else if(s1.equals("View"))
{
JFrame f = new JFrame("Pie Chart");
//f.setDefaultCloseOperation(JFrame.EXIT_ON_CL
OSE);
f.getContentPane().add(new PieChartPanel());
f.setSize(350,300);
f.setLocation(300,300);
f.setVisible(true);
}
else if(s1.equals("Download"))
{
System.out.println("button pressed");
String strd="";
int l,m,n;
String str5="select * from agri";
//System.out.println(str5);
try
{
ResultSet rst2=stmt.executeQuery(str5);
rst2.next();
l=Integer.parseInt(rst2.getString(3));
rst2.next();
m=Integer.parseInt(rst2.getString(3));
rst2.next();
n=Integer.parseInt(rst2.getString(3));
setBackground(Color.yellow);
setLayout(null);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (Exception e)
{
}
try
{
conn=DriverManager.getConnection("jdbc:odbc:sms");
stmt=conn.createStatement();
}
catch(Exception e)
{
}
add(ae1);
add(ae2);
add(ae3);
add(aet1);
add(aet2);
add(aet3);
add(aebu);
add(aebv);
add(aebd);
aebu.addActionListener(this);
aebv.addActionListener(this);
aebd.addActionListener(this);
ae1.setBounds(100,100,300,25);
ae2.setBounds(100,200,300,25);
ae3.setBounds(100,300,300,25);
aet1.setBounds(420,100,100,25);
aet2.setBounds(420,200,100,25);
aet3.setBounds(420,300,100,25);
aebu.setBounds(75,450,150,30);
aebv.setBounds(300,450,150,30);
aebd.setBounds(500,450,150,30);
}
public void actionPerformed(ActionEvent ae)
{
int i,j,k,r;
String s1=ae.getActionCommand();
if(s1.equals("Update"))
{
System.out.println("the button is pressed");
i=Integer.parseInt(aet1.getText());
j=Integer.parseInt(aet2.getText());
k=Integer.parseInt(aet3.getText());
//System.out.println(i);
//System.out.println(j);
//System.out.println(k);
try
{
ResultSet rst2=stmt.executeQuery(str5);
rst2.next();
l=Integer.parseInt(rst2.getString(3));
rst2.next();
m=Integer.parseInt(rst2.getString(3));
rst2.next();
n=Integer.parseInt(rst2.getString(3));
File f=new File("SCHOOLS.txt");
FileOutputStream fop=new FileOutputStrea
m(f);
if(f.exists())
{
strd="The number of Pre Primary schools
is: "+l+" ";
fop.write(strd.getBytes());
strd="The number of Primary schools is:
"+m+" ";
fop.write(strd.getBytes());
strd="The number of Higher Secondary sch
ools is: "+n+" ";
fop.write(strd.getBytes());
fop.flush();
fop.close();
System.out.println("The data has been wr
itten");
}
else
System.out.println("This file is
not exist");
JOptionPane.showMessageDialog(this,"DOWN
LOAD SUCCESSFULL!!",
"SUCCESS",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception e)
{
}
}
}
class HospitalPanel extends JPanel implements ActionListener
{
JTextField aht1,aht2,aht3;
JButton ahbu,ahbv,ahbd;
JLabel ah1,ah2,ah3;
Connection conn;
Statement stmt;
public HospitalPanel()
{
ah1 = new JLabel("Enter the number of Clinics");
ah2 = new JLabel("Enter the number of Vetenary Hospitals");
ah3 = new JLabel("Enter the number of Medical Colleges");
aht1= new JTextField(15);
aht2= new JTextField(15);
aht3= new JTextField(15);
ahbu=new JButton("Update");
ahbv=new JButton("View");
ahbd=new JButton("Download");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (Exception e)
{
}
try
{
conn=DriverManager.getConnection("jdbc:odbc:sms");
stmt=conn.createStatement();
}
catch(Exception e)
{
}
setBackground(Color.cyan);
setLayout(null);
add(ah1);
add(ah2);
add(ah3);
add(aht1);
add(aht2);
add(aht3);
add(ahbu);
add(ahbv);
add(ahbd);
ahbu.addActionListener(this);
ahbv.addActionListener(this);
ahbd.addActionListener(this);
ah1.setBounds(100,100,300,25);
ah2.setBounds(100,200,300,25);
ah3.setBounds(100,300,300,25);
aht1.setBounds(420,100,100,25);
aht2.setBounds(420,200,100,25);
aht3.setBounds(420,300,100,25);
ahbu.setBounds(75,450,150,30);
ahbv.setBounds(300,450,150,30);
ahbd.setBounds(500,450,150,30);
}
public void actionPerformed(ActionEvent ae)
{
int i,j,k,r;
String s1=ae.getActionCommand();
if(s1.equals("Update"))
{
//System.out.println("the button is pressed");
i=Integer.parseInt(aht1.getText());
j=Integer.parseInt(aht2.getText());
k=Integer.parseInt(aht3.getText());
//System.out.println(i);
//System.out.println(j);
//System.out.println(k);
try
{
setBackground(Color.cyan);
setLayout(null);
setBackground(Color.pink);
setLayout(null);
add(ap1);
add(ap2);
add(apt1);
add(apt2);
add(apbu);
add(apbv);
add(apbd);
apbu.addActionListener(this);
apbv.addActionListener(this);
apbd.addActionListener(this);
ap1.setBounds(100,100,300,25);
ap2.setBounds(100,200,300,25);
apt1.setBounds(420,100,100,25);
apt2.setBounds(420,200,100,25);
apbu.setBounds(75,450,150,30);
apbv.setBounds(300,450,150,30);
apbd.setBounds(500,450,150,30);
}
public void actionPerformed(ActionEvent ae)
{
int i,j,r;
String s1=ae.getActionCommand();
if(s1.equals("Update"))
{
//System.out.println("the button is pressed");
i=Integer.parseInt(apt1.getText());
j=Integer.parseInt(apt2.getText());
//k=Integer.parseInt(apt3.getText());
//System.out.println(i);
//System.out.println(j);
//System.out.println(k);
try
{
ResultSet rst2=stmt.executeQuery(str5);
rst2.next();
l=Integer.parseInt(rst2.getString(3));
rst2.next();
m=Integer.parseInt(rst2.getString(3));
n=l+m;
//rst2.next();
// n=Integer.parseInt(rst2.getString(3));
}
class PieChartPanel extends JPanel
{
Connection conn;
Statement stmt;
BufferedImage image;
final int PAD = 30;
Font font;
NumberFormat numberFormat;
public PieChartPanel()
{
font = new Font("Book Antiqua", Font.BOLD, 20);
numberFormat = NumberFormat.getPercentInstance();
addMouseListener(new Visibility(this));
addComponentListener(new ComponentAdapter()
{});
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (Exception e)
{
}
try
{
conn=DriverManager.getConnection("jdbc:odbc:sms");
stmt=conn.createStatement();
}
catch(Exception e)
{
}
}
protected void paintComponent(Graphics graphics)
{
super.paintComponent(graphics);
Graphics2D graphics2d = (Graphics2D)graphics;
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIAS
ING,
RenderingHints.VALUE_ANTIALIAS_ON);
createChartImage();
graphics2d.drawImage(image, 0, 0, this);
}
private void createChartImage()
{
int i,j=0;
String str1="select * from agri; ";
//String str2="select * from edu ;";
//String str3="select * from edu ";
int marks[]=new int[3];
try
{
ResultSet rst1=stmt.executeQuery(str1);
//ResultSet rst2=stmt.executeQuery(str2);
while(rst1.next())
{
i=Integer.parseInt(rst1.getString(3));
marks[j]=i;
j++;
}