0

There is a one J Frame in which i have put 2 panels & the Card layout is given to the both panels

by image J Frame having 2 panels one is

panel pane >>Where i an going to call panel1, panel2, panel3 where all that 3 panels have some controls like JtextField, jComboBox etc.

button pane >> in this the panel have button next & back when next is pressed (if panel pane Showing panel1 then) panel1 controls to be get validate

like that etc enter image description here

code is as follow



    package Code;

/**
 * 
 * @author Rohini
 */

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

public class InvoicePage extends JFrame implements ActionListener{

    JLabel newInvoic, invoiceNol, invoiceNo;
    JButton clinfoNext, payentryNext, termentryNext;
    JButton clinfoBack, payentryBack, termentryBack;


    JPanel buttonPane, clinfoBPane, payentryBPane, termentryBPane;
    JPanel panelpane, client_info, invoice_entry, term_entry;

    Container c = this.getContentPane();

    CardLayout cardmain, cardbutton;

    Font head = new Font("Times New Roman",Font.BOLD,20);
    Font subheadb = new Font("Times New Roman",Font.BOLD,14);
    Font subheadp = new Font("Times New Roman",Font.PLAIN,14);

    public InvoicePage() throws HeadlessException {

        super("Thane Bharat Sahakari Bank : New Invoice");

    //  initialization of variables
        cardmain  = new CardLayout();
        cardbutton = new CardLayout();        

        newInvoic = new JLabel("New Invoice");
        invoiceNol = new JLabel("Invoice No");
        invoiceNo = new JLabel("DB Value of id");

        clinfoNext = new JButton(" Next > > ");
        payentryNext = new JButton(" Next > > ");
        termentryNext = new JButton(" Next > > ");
        clinfoBack = new JButton(" < < Back ");
        payentryBack = new JButton(" < < Back ");
        termentryBack = new JButton(" < < Back ");

        buttonPane = new JPanel(cardbutton);
        clinfoBPane = new JPanel(null);
        payentryBPane = new JPanel(null);
        termentryBPane = new JPanel(null);

        panelpane = new JPanel(cardmain);
        client_info = new clientInfo();
        invoice_entry = new discription();
        term_entry = new termentry();

    //  setting properties of variabels

        panelpane.add(client_info,"Client_info");
        panelpane.add(invoice_entry,"invoice_entry");
        panelpane.add(term_entry,"term_entry");

        buttonPane.add(clinfoBPane,"clinfoBpane");
        buttonPane.add(payentryBPane,"payentryBPane");
        buttonPane.add(termentryBPane,"termentryBPane");

        clinfoBPane.add(clinfoBack);
        clinfoBPane.add(clinfoNext);
        payentryBPane.add(payentryBack);
        payentryBPane.add(payentryNext);
        termentryBPane.add(termentryBack);
        termentryBPane.add(termentryNext);

        newInvoic.setFont(head);
        invoiceNol.setFont(subheadb);
        invoiceNo.setFont(subheadp);

        clinfoNext.addActionListener(this);
        payentryNext.addActionListener(this);
        termentryNext.addActionListener(this);
        clinfoBack.addActionListener(this);
        payentryBack.addActionListener(this);
        termentryBack.addActionListener(this);

    //  setting Bounds
        Bounds(0,0);

    //  Adding Components
        c.add(newInvoic);
        c.add(invoiceNol);
        c.add(invoiceNo);
        c.add(buttonPane);
        c.add(panelpane);


    //  Form properties
        cardbutton.show(buttonPane,"clinfoBpane");
        cardmain.show(panelpane,"Client_info") ;        
        c.setLayout(null);
        c.setBackground(Color.WHITE);
        //clinfoBPane.setBackground(Color.WHITE);


        this.setResizable(true);
        this.setVisible(true);
        setDefaultCloseOperation(3);
        System.out.println("");
    }
    public void Bounds( int i, int j ){
        if(i == 0){
            newInvoic.setBounds(250,0,150,30);
            invoiceNol.setBounds(400,30,100,25);
            invoiceNo.setBounds(500,30,100,25);

            buttonPane.setBounds(0,410,610,50);
            panelpane.setBounds(0,50,610,350);
            clinfoNext.setBounds(430,5,150,30);
            clinfoBack.setBounds(25,5,150,30); 
            this.setSize(625,505);
            this.setLocation(300,150);
        }
        else if(i == 1){
            newInvoic.setBounds(350,0,150,30);
            invoiceNol.setBounds(600,30,100,25);
            invoiceNo.setBounds(700,30,100,25);

            buttonPane.setBounds(0,440,830,50);
            panelpane.setBounds(0,50,815,390);
            if(j == 0){
                payentryNext.setBounds(640,5,150,30);
                payentryBack.setBounds(30,5,150,30);
            }
            else if(j == 1){
                termentryNext.setBounds(640,5,150,30);
                termentryBack.setBounds(30,5,150,30);
            }           
            this.setSize(830,525);
            this.setLocation(200,100);
        }
        else{

        }
    }
        public void actionPerformed(ActionEvent ae){

            if(ae.getSource() == clinfoNext){
                cardbutton.show(buttonPane,"payentryBPane");
                cardmain.show(panelpane,"invoice_entry") ;
                Bounds(1,0);

            }
            else if(ae.getSource() == clinfoBack){
                this.dispose();
                Mainfrm mf = new Mainfrm();
                mf.setVisible(true);
            }
            else if((ae.getSource() == payentryNext)){
                Bounds(1,1);
                cardbutton.show(buttonPane,"termentryBPane");
                cardmain.show(panelpane,"term_entry") ;
            }
            else if(ae.getSource() == payentryBack){
                Bounds(0,0);
                cardbutton.show(buttonPane,"clinfoBpane");
                cardmain.show(panelpane,"Client_info") ;
            }
            else if(ae.getSource() == termentryBack){
                cardbutton.show(buttonPane,"payentryBPane");
                cardmain.show(panelpane,"invoice_entry") ;
                Bounds(1,0);
            }
            else if(ae.getSource() == termentryNext){
                JOptionPane.showConfirmDialog(this,"Are you sure that the invoice is over","Confirmation", JOptionPane.YES_NO_CANCEL_OPTION, 0);

            }
            else{

            }
        }
    public static void main(String []avi){

         new InvoicePage();
    } 
}
  • 1
    See [*Validating Input*](http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html#inputVerification) and edit your question to include an [sscce](http://sscce.org/) that shows any problems you encounter. – trashgod Feb 23 '13 at 06:15
  • sir i know about how to validate controls but i want the solution by using the card layout the panels which are created at separate class – Avinash Nivangune Feb 23 '13 at 07:01
  • Edit your question to clarify that. This [example](http://stackoverflow.com/a/5655843/230513) adds several instances of the _same_ class; you can use it as a basis for your [sscce](http://sscce.org/). – trashgod Feb 23 '13 at 07:06
  • sir i have seen that [link]http://stackoverflow.com/questions/5654926/implementing-back-forward-buttons-in-swing/5655843#5655843), i know how to change panels in the card layout – Avinash Nivangune Feb 23 '13 at 07:46
  • i have the above code the clientinfo, discription, termentry, are the out side panel class which i want to validate on the click of respective next button – Avinash Nivangune Feb 23 '13 at 08:32

1 Answers1

1

yes!! i got the answer

actually the outside panel variables are need to be have a public scope

&

(see above code)

JPanel panelpane, client_info, invoice_entry, term_entry;

i have created the instance of JPanel & initiate it with the outside panel i.e

   client_info = new clientInfo();
        invoice_entry = new discription();
        term_entry = new termentry();

instead of that the panels are doing

 JPanel panelpane, client_info, invoice_entry, term_entry;

by trying this problem get solve

  JPanel panelpane;
        clientInfo client_info;
        discription invoice_entry;

by this we can able to give the actionListner