Witshaper is the Professional (Computing Skills, English Learning and Soft Skills) Skill Development Training Center. We provide Professional IT Courses and Soft Skill Training in Dehradun to Students, Employees and organization. Who wish to pursue a career in IT Technology. Witshaper is led by a motivated team of IT experts and Soft Skill Professionals. We provide high quality trainings. Our Emphasis is on giving the practical knowledge to the students, so that they will get to know in depth and never forget what they opt, we provide to the students real learning environment. Witshaper prepares students and professionals to be the part of this growing industry. Be a part of Witshaper and get your dreams successful

Sunday 15 May 2016

Applet Program : JFrame and ActionListener

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

public class AddNewItem extends JFrame implements ActionListener
{
JLabel l1,l2,l3,l4;
JTextField t1,t2,t3,t4;
JButton b1,b2,b3;

AddNewItem()
{
l1=new JLabel("Product Name ");
l2=new JLabel("Product Price   ");
l3=new JLabel("Quantity           ");
l4=new JLabel("Product Type   ");
t1=new JTextField(15);
t2=new JTextField(15);
t3=new JTextField(15);
t4=new JTextField(15);
b1=new JButton("Clear");
b2=new JButton("Save ");
b3=new JButton("Close");
setLayout(new FlowLayout());
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
add(b1);
add(b2);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b2)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException cnfe)
{
System.out.println("Error :: "+cnfe.getMessage());
}
try
{
Connection con=DriverManager.getConnection("jdbc:odbc:Invent");
Statement st=con.createStatement();
String qry="Insert into prodmaster(prodnm,price,qty,prodtype,mfrdate) values('"+t1.getText()+"',"+t2.getText()+","+t3.getText()+",'"+t4.getText()+"',date())";
int ans=st.executeUpdate(qry);
if(ans==1)
System.out.println("Data Saved... ");
}
catch(SQLException se)
{
System.out.println("Problems :: "+se.getMessage());
}
}
}
public static void main(String ar[])
{
AddNewItem ani=new AddNewItem();
ani.setSize(300,250);
ani.setVisible(true);
}
}

No comments:

Post a Comment