i have a project which am half way done but on compling ma code it shows errors i need help to clean it
on login it should display a new JFrame with three labels and five buttons with actions
when the book id is entered it should retrive the book(bkbtn) the prvbtn button should take u to the previous book ,nxtbtn next book,lstbtn last book and fstbtn first book but using the book ID LIKE jv001 to move around thanx am in a hurry
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Login extends JFrame implements ActionListener
{
JButton SUBMIT;
JButton cancle;
JPanel panel;
int a;
JLabel label1,label2;
final JTextField text1,text2;
Login()
{
label1 = new JLabel();
label1.setText("Username: >>>");
label1.setFont(new java.awt.Font("Tahoma", 1, 11));
label1.setForeground(new java.awt.Color(204, 0, 0));
text1 = new JTextField(15);
label2 = new JLabel();
label2.setText("Password: >>>");
label2.setFont(new java.awt.Font("Tahoma", 1, 11));
label2.setForeground(new java.awt.Color(204, 0, 0));
text2 = new JPasswordField(15);
SUBMIT=new JButton("SUBMIT");
cancle=new JButton("CANCLE");
panel=new JPanel(new GridLayout(3,1));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(SUBMIT);
panel.add(cancle);
add(panel,BorderLayout.CENTER);
SUBMIT.addActionListener(this);
cancle.addActionListener(this);
setTitle("LOGIN FORM");
pack();
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==SUBMIT)
{
String value1=text1.getText();
String value2=text2.getText();
if (value1.equals("moses") && value2.equals("momo"))
{
book page=new book();
page.setVisible(true);
text1.setText("");
text2.setText("");
setVisible(false);
}
else
{
//System.out.println("enter the valid username and password");
JOptionPane.showMessageDialog(this,"Incorrect login or password Enter the valid username and password","Error",JOptionPane.ERROR_MESSAGE);
text1.setText("");
text2.setText("");
a=2;
}
}
else
{
System.exit(0);
}
}
}
class LoginDemo
{
public static void main(String arg[])
{
try
{
Login frame=new Login();
frame.setSize(600,400);
frame.setVisible(true);
frame.pack();
}
catch(Exception e)
{JOptionPane.showMessageDialog(null, e.getMessage());}
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class book extends JFrame implements ActionListener
{
JTextFeild cd,nm,qt;
JLabel jLabel1,jLabel2,jLabel3,jLabel4;
JButton fstbtn = new JButton();
JButton prvbtn = new JButton();
JButton nxtbtn = new JButton();
JButton lstbtn = new JButton();
Jbutton bkbtn=new JButton();
Container contentPane;
ResultSet rs;
PreparedStatement pst;
String strTemp,strSql,snm,sqt;
int qty;
JPanel panel,panel2;
String password,username,url;
Connection con;
public book()
{
panel=new JPane();
panel.setLayout(new GridLayout(3,2));
panel2=new JPane();
panel2.setLayout(new GridLayout(1,5));
cd=new JTextFeild(20);
nm=new JTextFeild(20);
qt=new JTextFeild(20);
jLabel1=new JLabel();
jLabel2=new JLabel();
jLabel3=new JLabel();
jLabel4=new JLabel();
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
jLabel1.setForeground(new java.awt.Color(204, 0, 0));
jLabel1.setText("Book ID");
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18));
jLabel2.setForeground(new java.awt.Color(204, 0, 0));
jLabel2.setText("Book Name");
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18));
jLabel3.setForeground(new java.awt.Color(204, 0, 0));
jLabel3.setText("Books Available");
fstbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
fstbtn.setForeground(new java.awt.Color(255, 0, 0));
prvbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
prvbtn.setForeground(new java.awt.Color(255, 0, 0));
nxtbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
nxtbtn.setForeground(new java.awt.Color(255, 0, 0));
lstbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
lstbtn.setForeground(new java.awt.Color(255, 0, 0));
bkbtn.setFont(new java.awt.Font("Tahoma", 1, 11));
bkbtn.setForeground(new java.awt.Color(255, 0, 0));
fstbtn.setText("l <");
prvbtn.setText("<<<");
nxtbtn.setText(">>>");
bkbtn.setText("Books");
lstbtn.setText("> l");
panel.add(jLabel);
panel.add(cd);
panel.add(jLabe2);
panel.add(nm);
panel.add(jLabe3);
panel.add(qt);
panel2.add(fstbtn);
panel2.add(prvbtn);
panel2.add(bkbtn);
panel2.add(nxtbtn);
panel2.add(lstbtn);
fstbtn.addActionListener(this);
prvbtn.addActionListener(this);
bkbtn.addActionListener(this);
nxtbtn.addActionListener(this);
lstbtn.addActionListener(this);
lstbtn.addActionListener(this);
contentPane=getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(panel,BorderLayout.PAGE_START);
contentPane.add(panel2,BorderLayout.PAGE_END);
con=this.getConnection();
pack();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
private string getConnection()
{
driver = "sun.jdbc.odbc.JdbcOdbcDriver";
url = "jdbc:odbc:test";
username = "";
password = "";
}
private Connection getConnection()
{
try
{
Class.forName(driver);
con=DriverManager.getConnection(url, username, password);
}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);
}
}
public void actionPerformed(ActionEvent e)
{
string cat,lbl,cat1,qt1;
cat=cd.getText();
lbl="TAKE BOOK";
int i=1;
if(e.getSource()==bkbtn)
if(bkbtn.getText()=="Books")
{
{
try
{
bkbtn.setText(lbl);
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
whihe(rs.next())
{
strTemp=rs.getString("BkName");
sqt=rs.getInt("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);
}
}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);
}
}
}
else
{
try
{
qt1=qt.getText();
qt1=qt1-1;
strSql="update books set BooksAvailable="+qt1+" where BkId like "+cat;
JOptionPane.showMessageDialog(this,"");
}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);
}
}
else if(e.getSource()==prvbtn)
{
try
{
cat1=cat.subString(0,4);
i--;
cat=cat1+i;
cd.setText(cat);
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
whihe(rs.next())
{
strTemp=rs.getString("BkName");
sqt=rs.getInt("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);
}
}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);
}
}
else if(e.getSource()==fstbtn)
{
try
{
cat1=cat.subString(0,4);
i=1;
cat=cat1+i;
cd.setText(cat);
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
whihe(rs.next())
{
strTemp=rs.getString("BkName");
sqt=rs.getInt("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);
}
}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);
}
}
else if(e.getSource()==nxtbtn)
{
try
{
cat1=cat.subString(0,4);
i++;
cat=cat1+i;
cd.setText(cat);
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
whihe(rs.next())
{
strTemp==rs.getString("BkName");
sqt=rs.getInt("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);
}
}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);
}
}
else if(e.getSource()==lstbtn)
{
try
{
cat1=cat.subString(0,4);
i=9;
cat=cat1+i;
cd.setText(cat);
strSql="select*from books where BkId like ?";
pst=con.prepareStatement(strSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pst.setString(1,cat);
rs=pst.executeQuery();
whihe(rs.next())
{
strTemp=rs.getString("BkName");
sqt=rs.getInt("BooksAvailable");
nm.setText(strTemp);
qt.setText(""+sqt);
}
}
catch(Exception ce)
{
JOptionPane.showMessageDialog(this,ce,"Error",JOptionPane.ERROR_MESSAGE);
}
}
}
}