Ask Experts Questions for FREE Help !
Ask
    suhas001's Avatar
    suhas001 Posts: 1, Reputation: 1
    New Member
     
    #1

    Feb 18, 2010, 09:19 AM
    java program error
    Sir, program is for managing account details using jdbc but ,there error like some variable not accessible in specefic block . Please solve this problem. If you can..
    //mypanel1-LogIn
    class mypanel1 extends JPanel
    {
    JTextField t1,t2;
    JButton b1,b2;
    mypanel1()
    {
    JLabel l1,l2;
    l1=new JLabel("User ID:");
    l2=new JLabel("Password:");
    t1=new JTextField();
    t2=new JTextField();
    b1=new JButton("Log In");
    b2=new JButton("Exit");

    setLayout(flowLayout);
    add(l1);
    add(t1);
    add(l2);
    add(l2);
    add(t2);
    add(b1);
    add(b2);
    }

    }

    //mypanel2
    class mypanel2 extends JPanel
    {
    JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,st;
    JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,srh ;
    JRadioButton rb1,rb2;
    JComboBox cb1,cb2;
    JButton j1,sb1;
    mypanel2()
    {
    t1=new JTextField();
    t2=new JTextField();
    t3=new JTextField();
    t4=new JTextField();
    t5=new JTextField();
    t6=new JTextField();
    t7=new JTextField();
    t8=new JTextField();
    t9=new JTextField();
    t10=new JTextField();
    t11=new JTextField();
    t12=new JTextField();
    st=new JTextField();

    l1= new JLabel("Customer Name:");
    l2= new JLabel("Customer ID:");
    l3= new JLabel("Flat:");
    l4= new JLabel("TEL NO:");
    l5= new JLabel("Building:");
    l6= new JLabel("Mobile NO:");
    l7= new JLabel("Area:");
    l8= new JLabel("Pin Code:");
    l9= new JLabel("City:");
    l10= new JLabel("NO. of Connection:");
    l11= new JLabel("Activation Date:");
    l12= new JLabel("Subscriber Charges:");
    l13= new JLabel("Status:");
    l14= new JLabel("Current Balance:");
    srh=new JLabel("Search:");

    j1=new JButton("Generate Bill");
    sb1=new JButton("Search");

    rb1=new JRadioButton("Mr.");
    rb2=new JRadioButton("Mrs.");


    String clist1[]={"Ozar","Nashik","Niphad","NashikRD"};
    String clist2[]={"Active","T.disconnected"};


    cb1=new JComboBox(clist1);
    cb2=new JComboBox(clist2);

    setLayout(null);

    rb1.setBounds(10,40,60,20);
    rb2.setBounds(80,00,60,100);
    l1.setBounds(10,100,100,20);
    t1.setBounds(110,100,180,20);
    l2.setBounds(220,100,80,20);
    t2.setBounds(10,100,160,20);
    l2.setBounds(320,100,80,20);
    t2.setBounds(400,100,80,20);
    l3.setBounds(10,135,80,20);
    t3.setBounds(110,135,80,20);
    l4.setBounds(320,135,80,20);
    t4.setBounds(400,135,80,20);
    l5.setBounds(10,170,80,20);
    t5.setBounds(110,170,100,20);
    l6.setBounds(320,170,80,20);
    t6.setBounds(400,170,80,20);
    l7.setBounds(10,205,80,20);
    cb1.setBounds(110,205,140,20);
    l8.setBounds(320,205,80,20);
    t7.setBounds(400,205,80,20);
    l9.setBounds(10,240,80,20);
    t8.setBounds(110,240,80,20);
    l10.setBounds(280,240,120,20);
    t9.setBounds(400,240,40,20);
    l11.setBounds(10,280,120,20);
    t10.setBounds(110,280,80,20);
    l12.setBounds(280,280,120,20);
    t11.setBounds(400,280,40,20);
    l13.setBounds(10,320,80,20);
    cb2.setBounds(110,320,80,20);
    l14.setBounds(280,320,100,20);
    t12.setBounds(400,320,40,20);

    j1.setBounds(150,420,250,20);

    srh.setBounds(180,40,150,20);
    st.setBounds(230,40,150,20);
    sb1.setBounds(400,40,80,20);

    add(rb1);add(rb2);add(l1);add(t1);add(l2);add(t2); add(l3);add(t3);
    add(l4);add(t4);add(l5);add(t5);add(l6);add(t6);ad d(l7);add(cb1);
    add(l8);add(t7);add(l8);add(t8);add(l9);add(l10);a dd(t9);add(l11);add(t10);
    add(l12);add(t11);add(l13);add(cb2);add(l14);add(t 12);

    add(j1);add(srh); add(st); add(sb1);

    }


    }
    //mypanel3
    class mypanel3 extends JPanel
    {
    JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15 ,t16,t17;
    JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15 ,l16,l17;
    JRadioButton rb1,rb2;
    mypanel3()
    {
    t1=new JTextField(); t2=new JTextField();
    t3=new JTextField(); t4=new JTextField();
    t5=new JTextField(); t6=new JTextField();
    t7=new JTextField(); t8=new JTextField();
    t9=new JTextField(); t10=new JTextField();
    t11=new JTextField(); t12=new JTextField();
    t13=new JTextField(); t14=new JTextField();
    t15=new JTextField(); t16=new JTextField();
    t17=new JTextField();

    l1= new JLabel("Bill no:");
    l2= new JLabel("Bill Date:");
    l3= new JLabel("Cust Name:");
    l4= new JLabel("Cust Id:");
    l5= new JLabel("Address:");
    l6= new JLabel("Moble:");
    l7= new JLabel("bill from Date");
    l8= new JLabel("Bill upto:");
    l9= new JLabel("Service Tax[%]:");
    l10= new JLabel("Education Tax[%]:");
    l11= new JLabel("Interest:");
    l12= new JLabel("Ent Tax:");
    l13= new JLabel("Vat:");
    l14= new JLabel("Total amount:");
    l15= new JLabel("Cash Mode:");
    l16= new JLabel("Deposit:");
    l17= new JLabel(");
    l17= new JLabel(");


    rb1=new JRadioButton("cash.");


    rb1=new JRadioButton("Cheq.");
    rb2=new JRadioButton("next");
    l1.setBounds(70,100,60,20); t1.setBounds(130,100,80,20);
    l2.setBounds(340,100,120,20); t2.setBounds(400,100,80,20);
    l3.setBounds(40,135,80,20); t3.setBounds(130,135,180,20);
    l4.setBounds(350,135,80,20); t4.setBounds(400,135,80,20);
    l5.setBounds(60,170,60,20); t5.setBounds(130,170,180,20);
    l6.setBounds(350,170,60,20); t6.setBounds(400,170,80,20);
    l7.setBounds(30,205,80,20); t7.setBounds(130,205,80,20);
    l8.setBounds(340,205,60,20); t8.setBounds(400,205,80,20);
    l9.setBounds(20,240,100,20); t9.setBounds(130,240,80,20);
    l10.setBounds(280,240,100,20); t10.setBounds(400,240,80,20);
    l11.setBounds(60,280,60,20); t11.setBounds(130,280,80,20);
    l12.setBounds(340,280,60,20); t12.setBounds(400,280,80,20);
    l13.setBounds(80,320,60,20); t13.setBounds(130,320,80,20);
    l14.setBounds(30,360,80,20); t14.setBounds(130,360,80,20);
    l15.setBounds(320,360,80,20); rb1.setBounds(400,360,80,20);
    rb2.setBounds(480,360,80,20); l16.setBounds(60,400,60,20);
    t15.setBounds(130,400,80,20); l17.setBounds(300,400,100,20);
    t16.setBounds(400,400,80,20);

    setLayout(null);

    add(l1); add(t1); add(l2); add(t2); add(l3);
    add(t3); add(l4); add(t4); add(l5); add(t5);
    add(l6); add(t6); add(l7); add(t7); add(l8); add(t8);
    add(l9); add(t9); add(l10); add(t10); add(l11);
    add(t11); add(l12); add(t12); add(l13); add(l13); add(l14);
    add(t14); add(l15); add(rb1); add(rb2); add(l16);
    add(t15); add(l17); add(t16);
    }
    }
    class mypanel6 extends JPanel
    {
    JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11;
    mypanel6()
    {
    b1=new JButton("Previous");
    b2=new JButton("First");
    b3=new JButton("Last");
    b4=new JButton("Add New");
    b6=new JButton(");
    b5=new JButton(");
    b7=new JButton("Modify");
    b6=new JButton("Delete");
    b7=new JButton("Save");
    b8=new JButton("Cancel");
    b9=new JButton("Back");
    b10=new JButton("Back to custmer information window");
    b11=new JButton("CTV SYSTEM");


    b11.setToolTipText("Error:");

    setLayout(new FlowLayout());

    add(b1); add(b2); add(b3); add(b4); add(b5);
    add(b6); add(b7); add(b8); add(b9); add(b10);
    add(b11);
    setVisible(true);
    }
    }

    //myframe class
    class myframe extends JFrame implements ActionListener
    {
    Connection cn1;
    Statement st1;
    ResultSet rs1;
    mypanel1 p1;
    mypanel2 p2;
    mypanel3 p3;
    mypanel6 p6;
    JLabel msg;
    int Flag;
    public myframe()
    {
    super("Database Error");
    p1=new mypanel1();
    p2=new mypanel2();
    p3=new mypanel3();
    p6=new mypanel6();

    Container c1=getContentPane();
    //mypanel4 p4=new mypanel4();
    //mypanel5 p5=new mypanel5();

    msg=new JLabel();
    msg.setBounds(330,360,120,20);
    p1.b1.addActionListener(this);
    p1.b2.addActionListener(this);
    p2.j1.addActionListener(this);
    p2.sb1.addActionListener(this);

    p6.b1.addActionListener(this); p6.b2.addActionListener(this);
    p6.b3.addActionListener(this); p6.b4.addActionListener(this);
    p6.b5.addActionListener(this); p6.b6.addActionListener(this);
    p6.b7.addActionListener(this); p6.b8.addActionListener(this);
    p6.b9.addActionListener(this); p6.b10.addActionListener(this);
    p6.b11.addActionListener(this);

    //p2.cb1.addItemListener();
    //p2.cb2.addItemListener();
    c1.add(msg);


    add(p1);
    //SetDefaultCloseOperation(EXIT_ON_CLOSE);
    try
    {
    setConnection();
    enablefields(true);

    if(rs1.next())
    {
    enablebuttons(true);
    showfields();
    }
    else
    {
    enablebuttons(true);
    p6.b8.setEnabled(false);
    p6.b9.setEnabled(false);
    p6.b5.setEnabled(true);
    }
    }
    catch(Exception e1)
    {
    JOptionPane.showMessageDialog(this,"Error:"+e1.get Message(),"Database Error",JOptionPane.ERROR_MESSAGE);
    }

    setSize(900,600);
    setVisible(true);

    }//myframe constructor
    void enablebuttons(boolean Flag)
    {
    p6.b1.setEnabled(Flag); p6.b2.setEnabled(Flag);
    p6.b3.setEnabled(Flag); p6.b4.setEnabled(Flag);
    p6.b5.setEnabled(Flag); p6.b6.setEnabled(Flag);
    p6.b7.setEnabled(Flag); p6.b8.setEnabled(!Flag);
    p6.b9.setEnabled(Flag); p6.b10.setEnabled(Flag);
    p6.b11.setEnabled(Flag);
    }


    void showfields()
    {
    try
    {
    p2.t1.setText(rs1.getString(1));
    p2.t2.setText(rs1.getString(2));
    p2.t3.setText(rs1.getString(3));
    p2.t4.setText(rs1.getString(4));
    p2.t5.setText(rs1.getString(1));
    }
    catch(Exception e1)
    {
    JOptionPane.showMessageDialog(this,"sun.jdbc.odbc. JdbcOdbcDriver"+e1.getMessage(),"jdbc:odbc:mydsn", JOptionPane.ERROR_MESSAGE);
    }
    }

    void enablefields(boolean flag)
    {
    p2.t1.setEnabled(flag); p2.t2.setEnabled(flag);
    p2.t3.setEnabled(flag); p2.t4.setEnabled(flag);
    p2.t5.setEnabled(flag); p2.t6.setEnabled(flag);
    p2.t7.setEnabled(flag); p2.t8.setEnabled(flag);
    p2.t9.setEnabled(flag); p2.t10.setEnabled(flag);
    p2.t11.setEnabled(flag); p2.t12.setEnabled(flag);
    p2.cb1.setEnabled(flag); p2.cb2.setEnabled(flag);
    }

    void setConnection()
    {
    try
    {
    Class.forName("Connection successful");
    Connection cn1=DriverManager.getConnection("select *from customer");
    System.out.println("sql error");
    st1=cn1.createStatement();
    rs1=st1.executeQuery(" error");
    }

    }
    public void actionPerformed(ActionEvent a1)
    {
    String s1=a1.getActionCommand();
    try
    {
    if(s1.equals(");
    }
    catch(SQLException e1)
    {
    System.out.println("))
    System.exit(0);
    else if(s1.equals(");
    }
    catch(Exception e1)
    {
    System.out.println("))
    {
    String login=p1.t1.getText();

    int pass=Integer.parseInt(p1.t2.getText());

    if(login.equals("s");
    }

    }
    public void actionPerformed(ActionEvent a1)
    {
    String s1=a1.getActionCommand();
    try
    {
    if(s1.equals("Log in Successfully"))
    System.exit(0);
    else if(s1.equals("South"))
    {
    String login=p1.t1.getText();

    int pass=Integer.parseInt(p1.t2.getText());

    if(login.equals("Login Fail:Invalid Password"))
    {
    if(pass==1)
    {
    //msg.setText("Login Fail:Invalid User ID");
    p1.t1.requestFocus();
    }
    }
    else if(s1.equals(");
    p1.setVisible(false);
    add(p2);
    add(p6,"))
    {
    p2.setVisible(false);
    add(p3);
    add(p6,"South");
    p2.setVisible(true);
    msg.setVisible(false);
    }
    else
    msg.setText("Back"))
    {
    p3.setVisible(false);
    add(p2);
    p2.setVisible(true);
    }
    else if(s1.equals(");

    }
    else
    {
    msg.setText("))
    {System.exit(0);
    /*p3.setVisible(false);
    add(p2);
    p2.setVisible(true);/*/
    }

    else if(s1.equals("Next");
    p1.t1.requestFocus();
    }
    }
    else if(s1.equals("Previous"))
    {
    p2.setVisible(false);
    add(p3);
    add(p6,"First");
    p3.setVisible(true);
    }
    else if(s1.equals("Last"))
    {
    p3.setVisible(false);
    add(p2);
    p2.setVisible(true);
    }
    else if(s1.equals("Add new"))
    {System.exit(0);
    /*p3.setVisible(false);
    add(p2);
    p2.setVisible(true);/*/
    }

    else if(s1.equals("None"))
    {
    if(rs1.next())
    showfields();
    else
    {
    rs1.last();
    showfields();
    }

    }
    else if(s1.equals("Cancel"))
    {
    if(rs1.previous())
    showfields();
    else
    {
    rs1.first();
    showfields();
    }

    }
    else if(s1.equals("Modify"))
    {
    rs1.first();
    showfields();
    }

    else if(s1.equals("Delete"))
    {
    rs1.last();
    showfields();
    }
    else if(s1.equals("Save"))
    {
    enablebuttons(false);
    //clearfields();
    enablefields(true);
    p2.cb1.setSelectedItem("None");
    p2.t2.requestFocus();
    Flag=1;
    }
    else if(s1.equals("select class name,"))
    {
    enablebuttons(true);
    enablefields(false);
    showfields();
    }
    else if(s1.equals(",JoptionPane.Information_MESSAGE);
    p2.cb1.requestFocus();
    }
    else
    {
    String vcname=p2.cb1.getSelectedItem();
    }
    rs1.updateInt(1,vrno);
    rs1.upateString(2,Vsnamne);
    sr1.upateInt(3,vm1);
    rs1.upateInt(4,vm2);
    rs1.upateInt(5,vm3);
    rs1.updateString(6,Vcname);
    if(Flag==1)
    rs1.insertRow();
    else
    {
    rs1.updateRow();
    rs1.refreshRow();
    }
    enablebutton(true);
    enablefields(false);
    }*/
    }
    catch(NumberFormatException e1)
    {
    //JOption.showMessageDialog(this,"))
    {
    enablebuttons(false);
    enablefields(true);
    p2.t2.requestFocus();
    Flag=1;
    }
    else if(s1.equals(",JoptionPane.WARNING_MESSAGE);
    p2.t3.requestFocus();
    }
    catch(Exception e1)
    {}

    }
    }
    class ctv
    {
    public static void main(String args[])
    {

    myframe f=new myframe();
    }
    }
    jmd814's Avatar
    jmd814 Posts: 10, Reputation: 2
    New Member
     
    #2

    Feb 19, 2010, 02:16 PM

    A stack trace or specific error message would be very very helpful.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Java program? [ 2 Answers ]

we have an assignment! but hold up! I would only ask what is the name of this code if I have fill up the blanks! code: puclic class problim{ public static void main(Stringarg){ int x=___; int y=___; while;(__<s){ x=____;

Error: Java Virtual Machine Launcher "Could not find the main class program will exit [ 3 Answers ]

Dear Sir / Madam, When I am trying to open .exj extension file, I am getting error as mentioned above. Please help me, whether I have to install any java module or something other has to be done. Thanks

Client server program in java [ 1 Answers ]

have a problem about writing client-server program. I want to write two (using TCP and UDP) different client and server programs which are used to transfer an ascii file. Some different information about this project is that the server will wait for client connection and when the client is...

Windows Service program using Java/ Javascript [ 1 Answers ]

I want to write a windows service program which will run at windows startup as service. This will check a mySQL table and do some updation work when a condition satisfied. How to implement it? Pl help for some books where to find this types of programming help.


View more questions Search