Wednesday, 6 November 2019

Swing Menu

Hi All,
Use this code.
-------------------------------------------------------

package placement;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
public class ITMenu extends Frame implements ActionListener{
TextArea ta;
public ITMenu(){
MenuBar mb=new MenuBar();
setMenuBar(mb);
  Menu menu1=new Menu("Task ");
                  Menu menu2=new Menu("Logout");
            MenuItem t1=new MenuItem("Add Requirements");
           
             MenuItem t2=new MenuItem("Add Sample Questions");
             menu1.add(t1);
             menu1.add(t2);
             MenuItem l1=new MenuItem("Logout");
             menu2.add(l1);
         
           
         
            mb.add(menu1);
            mb.add(menu2);
           
           
         
   menu1.addActionListener(this);
                   menu2.addActionListener(this);
                 
   setBackground(Color.getHSBColor(97,48,327));

   // add(ta, "Center");
    setTitle("IT Company");
    setSize(400,400);
    setLayout(null);
    setVisible(true);
}
    public void actionPerformed(ActionEvent e){
String str=e.getActionCommand();
if(str.equals("Logout"))
{new Homepage();
                                  setVisible(false);}
else if(str.equals("Add Requirements"))
    {
                                      //JOptionPane.showMessageDialog(null, "HUP");
     System.out.println("Entered");
                                     new Requirements();
    }
 
                               else if(str.equals("Add Sample Questions"))
    {

      new Addsample();
                                      setVisible(false);
    }
                               

else
{
try
      {
        FileReader fr = new FileReader(str);
        ta.setText("Folloiwing are file contents:\n\n");
        int temp;
        while( (temp = fr.read()) != -1)
        {
          char ch = (char) temp;
          String s1 = String.valueOf(ch);
          ta.append(s1);
}
        fr.close();
}
catch(IOException e1)
{
ta.setText("exception:"+e1);
}
}
}
public static void main(String args[])
{
new ITMenu();
}
}





Swing Login

Hi All,
Use this code
-----------------------------------------------
package placement;

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
//import javax.swing.JOptionPane;
import javax.swing.*;


class Login extends Frame implements ActionListener{
TextField tid;
String userid;
String driveid;
final JPasswordField tpass;
Button b1,b2;
   
Login(String userid,String password)
{
System.out.println(userid+" "+password);
       
setTitle("Login");
setVisible(true);   

setLayout(new FlowLayout());
this.setLayout(null);
Label uid=new Label("UserId:",Label.CENTER);
Label pass=new Label("Password:",Label.CENTER);



  tid=new TextField(20);
  tpass=new JPasswordField(20);
 


      uid.setBounds(70,90,90,60);
      pass.setBounds(70,130,90,60);
     


        tid.setBounds(200,100,90,20);
       tpass.setBounds(200,140,90,20);
     
    b1=new Button("Close");
        b1.setBounds(200,200,70,40);
b2=new Button("Login");
    b2.setBounds(280,200,70,40);
 

    b1.addActionListener(this);
b2.addActionListener(this);


add(tid);
add(tpass);



add(b1);
add(b2);

this.add(uid);
this.add(pass);



setSize(500,500);
setLayout(null);
tid.setText(userid);
tpass.setText(password);


setVisible(true);

}

 Login(){
     setBackground(Color.getHSBColor(97,92,247));
    setTitle("Login");
setVisible(true);   
      setLayout(new FlowLayout());
this.setLayout(null);
Label useid=new Label("UserId:",Label.CENTER);
Label password=new Label("password:",Label.CENTER);



  tid=new TextField(20);
  tpass=new JPasswordField(20);
 



      useid.setBounds(70,90,90,60);
      password.setBounds(70,130,90,60);
     


        tid.setBounds(200,100,90,20);
        tpass.setBounds(200,140,90,20);
       

    b1=new Button("Close");
        b1.setBounds(200,200,70,40);
b2=new Button("Login");
    b2.setBounds(280,200,70,40);
   

    b1.addActionListener(this);
b2.addActionListener(this);


add(tid);
add(tpass);



add(b1);
add(b2);


this.add(useid);
this.add(password);




setSize(400,350);
setLayout(null);
setVisible(true);
                               
}
public void actionPerformed(ActionEvent e)
{
String str=e.getActionCommand();
              if(str.equals("Close"))
{
                    int confirm = JOptionPane.showOptionDialog(
             null, "Are You Sure to Close Application?",
             "Exit Confirmation", JOptionPane.YES_NO_OPTION,
             JOptionPane.QUESTION_MESSAGE, null, null, null);
        if (confirm == 0) {
            new Homepage();
           setVisible(false);
       
    }

                    setVisible(false);
}
if(str.equals("Login"))
{
String useid=tid.getText();
                                        String drive=tid.getText();
String password=new String(tpass.getPassword());
                                         userid=useid;
                                         driveid=drive;
                                         setVisible(false);


try{
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/placement","root","");
   //here sonoo is database name, root is username and password
    Statement stmt=con.createStatement();
                                    String qr="select * from login where id='"+userid+"'and password='"+password+"'and status='1'";
                                    System.out.println(qr);
    ResultSet rs=stmt.executeQuery(qr);
  int flag=0;
                                   while(rs.next())
                                   {
                                       flag=1;
                                       String type=rs.getString("type");
                                       if(type.equals("po"))
                                       {
                                         POmenu pomenu=new POmenu(driveid);
                                         pomenu.setVisible(true);
                                       }
                                       else if(type.equals("student"))
                                       {
                                         StudMenu studmenu=new StudMenu(userid);
                                         studmenu.setVisible(true);
                                       }
                                       else if(type.equals("company"))
                                       {
                                         ITMenu itmenu=new ITMenu();
                                         itmenu.setVisible(true);
                                       }
                                        else if(type.equals("Admin"))
                                       {
                                         AdminMenu adminmenu=new AdminMenu();
                                         adminmenu.setVisible(true);
                                       }
                                   }
                                  if(flag==0)
                                 
                                      JOptionPane.showMessageDialog(null,"Invalid Username or Password,Try Again");
                                 
    con.close();
}
catch(Exception e1)
{
System.out.println(" Error :"+e1);
}
}




/*if(str.equals("update"))
{
String id=tid.getText();
String password=tpass.getText();
String type=ttype.getText();
String statuts=tstat.getText();

try{
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/placement","root","");
   //here sonoo is database name, root is username and password
    Statement stmt=con.createStatement();
    stmt.executeUpdate("update fund set password='"+tf2.getText()+"',type='"+tf3.getText()+"',amt='"+tf4.getText()+"',date='"+tf5.getText()+"',actcredited='"+tf6.getText()+"' where id='"+tf1.getText()+"'");
   // ResultSet rs=stmt.executeQuery("select * from tbl_job");
   // while(rs.next())
   // System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));
    con.close();
}
catch(Exception e1)
{
System.out.println(e1);
}
}*/
}
public static void main(String args[])
{
new Login();
}
}






Swing Delete

Hi All,
Use this code
--------------------------------------------
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package placement;

/**
 *
 * @author HUPA
 */
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;
import java.sql.*;

class POview extends JFrame

                {

private JPanel topPanel ;

private JTable table;

private JScrollPane scrollPane;

private String[] columnNames= new String[7];

private String[][] dataValues=new String[10][9] ;
Connection con;
Statement stmt;

public POview()

    {

setTitle("View Reg");

setSize(1000,300);

topPanel= new JPanel();

topPanel.setLayout(new BorderLayout());

getContentPane().add(topPanel);

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

WindowListener exitListener = new WindowAdapter() {

    @Override
    public void windowClosing(WindowEvent e) {
        int confirm = JOptionPane.showOptionDialog(
             null, "Are You Sure to Close Application?",
             "Exit Confirmation", JOptionPane.YES_NO_OPTION,
             JOptionPane.QUESTION_MESSAGE, null, null, null);
        if (confirm == 0) {
           setVisible(false);
        }
    }
};
addWindowListener(exitListener);
/*
columnNames=new String[] {"Column 1" , "Column 2" , "Column 3"};

dataValues = new String[][]     {

                                                {"1","2","3"},

                                                {"4","5","6"},

                                                {"7","8","9"}

                                            };
                                            */
   //////
    columnNames = new String[] {
               "pid", "Name", "Address", "PhNo ","Email","Qualification","YoE"

        };
          //create table with data
        try{
    Class.forName("com.mysql.jdbc.Driver");
     con=DriverManager.getConnection("jdbc:mysql://localhost:3306/placement","root","");
    //here sonoo is database name, root is username and password
     stmt=con.createStatement();
    //stmt.executeUpdate("insert into parol_request values('"+prison_id+"','123','1973-10-12','hfdjfsdjflejre','out')");
    ResultSet rs=stmt.executeQuery("select * from poreg");
    int i=0;
   while(rs.next()){
  dataValues[i][0]=rs.getString(1);
    dataValues[i][1]=rs.getString(2);
    dataValues[i][2]=rs.getString(3);
    dataValues[i][3]=rs.getString(4);
    dataValues[i][4]=rs.getString(5);
                                                                        dataValues[i][5]=rs.getString(6);
                                                                        dataValues[i][6]=rs.getString(7);

   //System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));

    i=i+1;
    }
    //con.close();
    }catch(Exception e1){ System.out.println(e1);}

    ///////////////

 TableModel model=new myTableModel();

 table =new JTable( );

 table.setRowHeight(20);

 table.setModel(model);

 scrollPane=new JScrollPane(table);

  topPanel.add(scrollPane,BorderLayout.CENTER);

  table.addMouseListener(new java.awt.event.MouseAdapter()

            {

public void mouseClicked(java.awt.event.MouseEvent e)

{

int row=table.rowAtPoint(e.getPoint());

int col= table.columnAtPoint(e.getPoint());

JOptionPane.showMessageDialog(null," Value in the cell deleted :"+ " " +table.getValueAt(row,col).toString());
String sql="delete from poreg where POid='"+table.getValueAt(row,0).toString()+"'";
System.out.println(""+sql);
try{
//con.open();
stmt.executeUpdate(sql);
//con.close();
}
catch(Exception e1)
{

}
System.out.println(" Value in the cell deleted :"+ " " +sql+" "+table.getValueAt(row,col).toString());

}

}

);

}

            public class myTableModel extends DefaultTableModel

                                                                                    {

                                                    myTableModel( )

                                                 {

                                                   super(dataValues,columnNames);

                                                   System.out.println("Inside myTableModel");

                                                 }

                                    public boolean isCellEditable(int row,int cols)

                                     {

                                   return false;

                                    }

                                    }

            public static void main(String args[])

            {

            POview mainFrame=new POview();

            mainFrame.setVisible(true);

            }

                        }

Swing Approve

Hi All,
Use this code
----------------------------------------------

package placement;
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;
import java.sql.*;

class Loginview extends JFrame

                {

private JPanel topPanel ;

private JTable table;

private JScrollPane scrollPane;

private String[] columnNames= new String[4];

private String[][] dataValues=new String[10][9] ;
Connection con;
Statement stmt;

public Loginview()

    {

setTitle("View Log");

setSize(1000,300);

topPanel= new JPanel();

topPanel.setLayout(new BorderLayout());

getContentPane().add(topPanel);

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

WindowListener exitListener = new WindowAdapter() {

    @Override
    public void windowClosing(WindowEvent e) {
        int confirm = JOptionPane.showOptionDialog(
             null, "Are You Sure to Close Application?",
             "Exit Confirmation", JOptionPane.YES_NO_OPTION,
             JOptionPane.QUESTION_MESSAGE, null, null, null);
        if (confirm == 0) {
           setVisible(false);
        }
    }
};
addWindowListener(exitListener);
/*
columnNames=new String[] {"Column 1" , "Column 2" , "Column 3"};

dataValues = new String[][]     {

                                                {"1","2","3"},

                                                {"4","5","6"},

                                                {"7","8","9"}

                                            };
                                            */
   //////
    columnNames = new String[] {
               "Id", "Password","Type","Status"

        };
          //create table with data
        try{
    Class.forName("com.mysql.jdbc.Driver");
     con=DriverManager.getConnection("jdbc:mysql://localhost:3306/placement","root","");
    //here sonoo is database name, root is username and password
     stmt=con.createStatement();
    //stmt.executeUpdate("insert into parol_request values('"+prison_id+"','123','1973-10-12','hfdjfsdjflejre','out')");
    ResultSet rs=stmt.executeQuery("select * from login where status='0' and type='PO'");
    int i=0;
   while(rs.next()){
  dataValues[i][0]=rs.getString(1);
    dataValues[i][1]=rs.getString(2);
    dataValues[i][2]=rs.getString(3);
                                                                        dataValues[i][3]=rs.getString(4);
   
   //System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));

    i=i+1;
    }
    //con.close();
    }catch(Exception e1){ System.out.println(e1);}

    ///////////////

 TableModel model=new myTableModel();

 table =new JTable( );

 table.setRowHeight(20);

 table.setModel(model);

 scrollPane=new JScrollPane(table);

  topPanel.add(scrollPane,BorderLayout.CENTER);

  table.addMouseListener(new java.awt.event.MouseAdapter()

            {

public void mouseClicked(java.awt.event.MouseEvent e)

{

int row=table.rowAtPoint(e.getPoint());

int col= table.columnAtPoint(e.getPoint());

JOptionPane.showMessageDialog(null," Placement Officer Approved :"+ " " +table.getValueAt(row,0).toString());
String sql="update login set status='1' where id='"+table.getValueAt(row,0).toString()+"'";
System.out.println(""+sql);
try{
//con.open();
stmt.executeUpdate(sql);
//con.close();
}
catch(Exception e1)
{

}
System.out.println(" Value in the cell deleted :"+ " " +sql+" "+table.getValueAt(row,col).toString());

}

}

);

}

            public class myTableModel extends DefaultTableModel

                                                                                    {

                                                    myTableModel( )

                                                 {

                                                   super(dataValues,columnNames);

                                                   System.out.println("Inside myTableModel");

                                                 }

                                    public boolean isCellEditable(int row,int cols)

                                     {

                                   return false;

                                    }

                                    }

            public static void main(String args[])

            {

            Loginview mainFrame=new Loginview();

            mainFrame.setVisible(true);

            }

                        }

Home Page Swing

Hi All,
See the home page
------------------------------------------------
package placement;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Homepage extends JFrame implements ActionListener
{
JButton b1,b2,b3,b4;
JLabel l1;
    public Homepage()
    {
    setTitle("home page");
    setSize(500,500);
    setLocationRelativeTo(null);
    setVisible(true);

    setLayout(new BorderLayout());
    setContentPane(new JLabel(new ImageIcon("C:\\Users\\User\\Documents\\NetBeansProjects\\Placement\\src\\placement\\SSMS.jpg")));
 
        setLayout(null);
         setVisible(true);
        // Homepage.setResizable(false);
        l1=new JLabel("REMINDER MANAGEMENT SYSTEM");
        l1.setFont(new Font("Courier New", Font.BOLD, 30));
        //l1.setBounds(120, 10, 680, 30);
        l1.setForeground(Color.MAGENTA);
        b1=new JButton("Add Reminder");
         b1.setBounds(380,80,180,30);
        b2=new JButton("View Reminder");
         b2.setBounds(380,140,180,30);
        b3=new JButton("Update Reminder");
         b3.setBounds(380,200,180,30);
        b4=new JButton("Login");
         b4.setBounds(570,270,90,30);
       
        add(l1);
        add(b1);
        add(b2);
       
        //this.add(l1);
        b1.addActionListener(this);

b2.addActionListener(this);



        // Just for refresh :) Not optional!
       
        setSize(700,380);
     

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

WindowListener exitListener = new WindowAdapter() {

    @Override
    public void windowClosing(WindowEvent e) {
        int confirm = JOptionPane.showOptionDialog(
             null, "Are You Sure to Close Application?",
             "Exit Confirmation", JOptionPane.YES_NO_OPTION,
             JOptionPane.QUESTION_MESSAGE, null, null, null);
        if (confirm == 0) {
           setVisible(false);
        }
    }
};
addWindowListener(exitListener);
    }
public void actionPerformed(ActionEvent e)
        {
                String str=e.getActionCommand();
                if(str.equals("Add Reminder"))
                {
                        Skill mainFrame=new Skill();

                        mainFrame.setVisible(true);
                        setVisible(false);
                }
else if(str.equals("View Reminder"))
                                                                                                              {


            Skillview mainFrame=new Skillview();

            mainFrame.setVisible(true);
            setVisible(false); }





}
public static void main(String args[])
{
new Homepage();
}
}

Swing view

Hi All,
Use this code.
----------------------------------

package placement;


import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;
import java.sql.*;

class Skillview extends JFrame

                {

private JPanel topPanel ;

private JTable table;

private JScrollPane scrollPane;

private String[] columnNames= new String[3];

private String[][] dataValues=new String[10][9] ;
Connection con;
Statement stmt;

public Skillview()

    {

setTitle("View Reg");

setSize(1000,300);

topPanel= new JPanel();

topPanel.setLayout(new BorderLayout());

getContentPane().add(topPanel);

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

WindowListener exitListener = new WindowAdapter() {

    @Override
    public void windowClosing(WindowEvent e) {
        int confirm = JOptionPane.showOptionDialog(
             null, "Are You Sure to Close Application?",
             "Exit Confirmation", JOptionPane.YES_NO_OPTION,
             JOptionPane.QUESTION_MESSAGE, null, null, null);
        if (confirm == 0) {
           setVisible(false);
           new Homepage();
        }
    }
};
addWindowListener(exitListener);
/*
columnNames=new String[] {"Column 1" , "Column 2" , "Column 3"};

dataValues = new String[][]     {

                                                {"1","2","3"},

                                                {"4","5","6"},

                                                {"7","8","9"}

                                            };
                                            */
   //////
    columnNames = new String[] {
               "RId", "Date", "Description"

        };
          //create table with data
        try{
    Class.forName("com.mysql.jdbc.Driver");
     con=DriverManager.getConnection("jdbc:mysql://localhost:3306/placement","root","");
    //here sonoo is database name, root is username and password
     stmt=con.createStatement();
    //stmt.executeUpdate("insert into parol_request values('"+prison_id+"','123','1973-10-12','hfdjfsdjflejre','out')");
    ResultSet rs=stmt.executeQuery("select * from reminder");
    int i=0;
   while(rs.next()){
  dataValues[i][0]=rs.getString(1);
    dataValues[i][1]=rs.getString(2);
    dataValues[i][2]=rs.getString(3);
   
   //System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));

    i=i+1;
    }
    //con.close();
    }catch(Exception e1){ System.out.println(e1);}

    ///////////////

 TableModel model=new myTableModel();

 table =new JTable( );

 table.setRowHeight(20);

 table.setModel(model);

 scrollPane=new JScrollPane(table);

  topPanel.add(scrollPane,BorderLayout.CENTER);

  table.addMouseListener(new java.awt.event.MouseAdapter()

            {

public void mouseClicked(java.awt.event.MouseEvent e)

{

int row=table.rowAtPoint(e.getPoint());

int col= table.columnAtPoint(e.getPoint());

JOptionPane.showMessageDialog(null," Value in the cell deleted :"+ " " +table.getValueAt(row,col).toString());
//String sql="delete from skills where skid='"+table.getValueAt(row,0).toString()+"'";
Skill hup=new Skill(table.getValueAt(row,0).toString(),table.getValueAt(row,1).toString(),table.getValueAt(row,2).toString());
hup.setVisible(true);
//System.out.println(""+sql);
try{
//con.open();
//stmt.executeUpdate(sql);
//con.close();
}
catch(Exception e1)
{

}
//System.out.println(" Value in the cell Updated :"+ " " +sql+" "+table.getValueAt(row,col).toString());

}

}

);
setVisible(true);
}

            public class myTableModel extends DefaultTableModel

                                                                                    {

                                                    myTableModel( )

                                                 {

                                                   super(dataValues,columnNames);

                                                   System.out.println("Inside myTableModel");

                                                 }

                                    public boolean isCellEditable(int row,int cols)

                                     {

                                   return false;

                                    }

                                    }

            public static void main(String args[])

            {

            Skillview mainFrame=new Skillview();

            mainFrame.setVisible(true);

            }

                        }

Swing Save

Hi,
Pls use this code

------------------------------------------------------

package placement;



import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.JOptionPane;

class Skill extends Frame implements ActionListener{

TextField rid,rdate,rdescription;
Button b1,b2;
Skill(String skid,String name,String description)
{
System.out.println(skid+" "+name+" "+description+"')");

     setBackground(Color.getHSBColor(45,92,100));

setLayout(new FlowLayout());
this.setLayout(null);
Label id=new Label("Skid:",Label.CENTER);
Label nam=new Label("Name:",Label.CENTER);
Label des=new Label("Description:",Label.CENTER);

               
               


  rid=new TextField(20);
  rdate=new TextField(20);
                  rdescription=new TextField(20);



      id.setBounds(70,90,90,60);
      nam.setBounds(70,130,90,60);
      des.setBounds(70,170,90,60);
   


        rid.setBounds(200,100,90,20);
        rdate.setBounds(200,140,90,20);
        rdescription.setBounds(200,180,90,20);
   
             

    b1=new Button("Update");
            b1.setBounds(200,240,70,40);
    b2=new Button("close");
    b2.setBounds(280,240,70,40);
    //b3=new Button("close");
    //b3.setBounds(360,240,70,40);

    b1.addActionListener(this);
b2.addActionListener(this);
//b3.addActionListener(this);

add(rid);
add(rdate);
add(rdescription);


add(b1);
add(b2);
//add(b3);
this.add(id);
this.add(nam);
this.add(des);



setSize(700,700);
setLayout(null);
rid.setText(skid);
rdate.setText(name);
                                    rdescription.setText(description);
                                        rid.setEnabled(false);


}
public void autoid()
{
    try{
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/placement","root","");
   //here sonoo is database name, root is username and password
    Statement stmt=con.createStatement();
                                    String qr="select max(rid) as mid from reminder";
                                    System.out.println(qr);
    ResultSet rs=stmt.executeQuery(qr);
  int flag=0;
                                  int mid=0;
                                   while(rs.next())
                                   {
                                     
                                        mid=rs.getInt("mid");
                                        mid=mid+1;
                                     
                                   }
                                  JOptionPane.showMessageDialog(null,"New id "+mid);
                                  rid.setText(""+mid);
                                  rid.setEnabled(false);
                                con.close();
}
catch(Exception e1)
{
System.out.println(e1);
}

}


 Skill(){
     setBackground(Color.getHSBColor(97,92,247));

setLayout(new FlowLayout());
this.setLayout(null);
                 Label id=new Label("RId:",Label.CENTER);
Label name=new Label("Reminder Date:",Label.CENTER);
Label description=new Label("Description:",Label.CENTER);



          rid=new TextField(20);
  rdate=new TextField(20);
                 rdescription=new TextField(20);


               id.setBounds(70,90,90,60);
      name.setBounds(70,130,90,60);
      description.setBounds(70,170,90,60);
   


        rid.setBounds(200,110,90,20);
        rdate.setBounds(200,150,90,20);
       rdescription.setBounds(200,190,90,20);
     

    b1=new Button("submit");
        b1.setBounds(200,240,70,40);
b2=new Button("close");
    b2.setBounds(280,240,70,40);
    //b3=new Button("close");
    //b3.setBounds(360,240,70,40);

    b1.addActionListener(this);
b2.addActionListener(this);
//b3.addActionListener(this);
               
                        add(rid);
add(rdate);
add(rdescription);

                       

add(b1);
add(b2);
// add(b3);
this.add(id);
this.add(name);
this.add(description);




setSize(500,400);
setLayout(null);
setVisible(true);
                                autoid();
                               
}
public void actionPerformed(ActionEvent e)
{
String str=e.getActionCommand();
              if(str.equals("close"))
{
                    int confirm = JOptionPane.showOptionDialog(
             null, "Are You Sure to Close Application?",
             "Exit Confirmation", JOptionPane.YES_NO_OPTION,
             JOptionPane.QUESTION_MESSAGE, null, null, null);
        if (confirm == 0) {
            new Homepage();
           setVisible(false);
       
    }
}
//setVisible(false);

if(str.equals("submit"))
{
        String id=rid.getText();
                                        String name=rdate.getText();
                                        String description=rdescription.getText();


                                          if(id.equals(""))
                                        {
                                            JOptionPane.showMessageDialog(null, "Enter the id");
                                            rid.requestFocusInWindow();
                                          }
                                         else  if(description.equals(""))
                                        {
                                            JOptionPane.showMessageDialog(null, "Enter the Description");
                                            rdescription.requestFocusInWindow();
                                         }
                                          else  if(name.equals(""))
                                        {
                                            JOptionPane.showMessageDialog(null, "Enter the Date");
                                            rdate.requestFocusInWindow();
                                         }
                                          else  if(name.equals(""))
                                        {
                                            JOptionPane.showMessageDialog(null, "Enter the Date");
                                            rdate.requestFocusInWindow();
                                         }
                                         else
                                         {
                               
                                       
                                       
try{
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/placement","root","");
   //here sonoo is database name, root is username and password
    Statement stmt=con.createStatement();
                                    String qr="insert into reminder values('"+id+"','"+name+"','"+description+"')";
                                    System.out.println(qr);
    stmt.executeUpdate(qr);
   JOptionPane.showMessageDialog(null,"Reminder Added");
                                    // ResultSet rs=stmt.executeQuery("select * from tbl_job");
   // while(rs.next())
   // System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));
    con.close();
}
catch(Exception e1)
{
System.out.println(e1);
}
}
                                        }

                                if(str.equals("Update"))
{
        String id=rid.getText();
                                        String name=rdate.getText();
                                       

String description=rdescription.getText();
                                          if(id.equals(""))
                                        {
                                            JOptionPane.showMessageDialog(null, "Enter the id");
                                            rid.requestFocusInWindow();
                                          }
                                         else  if(name.equals(""))
                                        {
                                            JOptionPane.showMessageDialog(null, "Enter the Date");
                                            rdate.requestFocusInWindow();
                                         }
                                          else  if(description.equals(""))
                                        {
                                            JOptionPane.showMessageDialog(null, "Enter the Description");
                                            rdescription.requestFocusInWindow();
                                         }
                                         else
                                         {
                               
                                       
                                       
try{
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/placement","root","");
   //here sonoo is database name, root is username and password
    Statement stmt=con.createStatement();
                                    String qr="update  reminder set rdate='"+name+"',rdescription='"+description+"' where rid='"+id+"'";
                                    System.out.println(qr);
    stmt.executeUpdate(qr);
   JOptionPane.showMessageDialog(null,"Reminder Updated");
                                    // ResultSet rs=stmt.executeQuery("select * from tbl_job");
   // while(rs.next())
   // System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));
    con.close();
}
catch(Exception e1)
{
System.out.println(e1);
}
}
                                        }


                                    if(str.equals("aaa"))
{
/*String id=tf1.getText();
String fname=tf2.getText();
String des=tf3.getText();
String amt=tf4.getText();
a String date=tf5.getText();
String actcredited=tf6.getText();

try{
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/fund","root","");
   //here sonoo is database name, root is username and password
    Statement stmt=con.createStatement();
    stmt.executeUpdate("update fund set fname='"+tf2.getText()+"',des='"+tf3.getText()+"',amt='"+tf4.getText()+"',date='"+tf5.getText()+"',actcredited='"+tf6.getText()+"' where id='"+tf1.getText()+"'");
   // ResultSet rs=stmt.executeQuery("select * from tbl_job");
   // while(rs.next())
   // System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));
    con.close();
}
catch(Exception e1)
{
System.out.println(e1);
}
                                                 *
                                                 * */
}
}
public static void main(String args[])
{
new Skill();
}
}






Swing Menu

Hi All, Use this code. ------------------------------------------------------- package placement; import java.awt.*; import java.io.*...