users@glassfish.java.net

can someone Help , newbies needs help!!

From: <glassfish_at_javadesktop.org>
Date: Fri, 17 Apr 2009 13:25:33 PDT

i tried to make this work, but i m unable to find out why the component overlap when i switch between menu items. thanks




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




public class BookStoreProgram extends JFrame {
//variables Book info
private JLabel HeadingLabel;
private JLabel FilerLabel;
private JLabel NameLabel;
private JLabel ISBNLabel;
private JLabel PriceLabel;
private JLabel Author1Label;
private JLabel Author2Label;
private JLabel Author3Label;
private JLabel Author4Label;
private JLabel QuantityLabel;
private JLabel PublisherLabel;
private JLabel YearOfPublicationLabel;
private JTextField NameText;
private JTextField IsbnText;
private JTextField PriceText;
private JTextField Author1Text;
private JTextField Author2Text;
private JTextField Author3Text;
private JTextField Author4Text;
private JTextField QuantityText;
private JTextField PublisherText;
private JTextField YearOfPublicationText;
private JButton SubmitB, ClearB ;

// variables Member info
private JLabel HeadingLabelM;
private JLabel FilerLabelM ;
private JLabel MemberNameM;
private JLabel MemberIdM;
private JLabel NumberBookbought;
private JLabel AmountSpent;
private JLabel MemberShip;
private JTextField NameTextM;
private JTextField MemberIdText;
private JTextField NumberBookboughtText;
private JTextField AmountSpentText;
private JTextField MemberShipText;
private JButton SubmitBM, ClearBM ;









public BookStoreProgram() {
super("Book Store!");
//setTitle("Book Store");
setSize(750, 850);

// Creates a menubar for a JFrame
JMenuBar menuBar = new JMenuBar();

// Add the menubar to the frame
setJMenuBar(menuBar);

// Define and add two drop down menu to the menubar

JMenu fileMenu = new JMenu("File");
JMenu searchMenu = new JMenu("Search");
menuBar.add(fileMenu);
menuBar.add(searchMenu);

// Create and add simple menu item to one of the drop down menu

JMenuItem BookAction = new JMenuItem("Add New Book");
JMenuItem MemberAction = new JMenuItem("Add New Member");
JMenuItem SearchbookAction = new JMenuItem("Search for Book");
JMenuItem SearchmemberAction = new JMenuItem("Search for Member");

// add menu items to the right menu.

fileMenu.add(BookAction);
fileMenu.add(MemberAction);
searchMenu.add(SearchbookAction);
searchMenu.add(SearchbookAction);

//Container pane = getContentPane();
//pane.setLayout(new GridLayout(1,1));

BookAction.addActionListener( new ActionListener() {

public void actionPerformed(ActionEvent e ) {

Container pane = getContentPane();

pane.setLayout(new GridLayout(12,2));

//pbHandlerSubmit = new ButtonHandler();

HeadingLabel = new JLabel("Enter Info.", SwingConstants.CENTER);
FilerLabel = new JLabel("Filer Label",SwingConstants.CENTER);
NameLabel = new JLabel("Customer Name:",SwingConstants.CENTER);
ISBNLabel = new JLabel("ISBN :",SwingConstants.CENTER);
PriceLabel = new JLabel("Price in Dollars:",SwingConstants.CENTER);
Author1Label = new JLabel("Author 1 :", SwingConstants.CENTER);
Author2Label = new JLabel("Author 2 :", SwingConstants.CENTER);
Author3Label = new JLabel("Author 3 :", SwingConstants.CENTER);
Author4Label = new JLabel("Author 4 :", SwingConstants.CENTER);
QuantityLabel = new JLabel("Quantity :", SwingConstants.CENTER);
PublisherLabel = new JLabel("Publisher:", SwingConstants.CENTER);
YearOfPublicationLabel = new JLabel("Year of Publication:", SwingConstants.CENTER);
NameText = new JTextField("");
IsbnText = new JTextField("");
PriceText = new JTextField("");
Author1Text = new JTextField("");
Author2Text = new JTextField("");
Author3Text = new JTextField("");
Author4Text = new JTextField("");
QuantityText = new JTextField("");
PublisherText = new JTextField("");
YearOfPublicationText = new JTextField("");
SubmitB = new JButton("Submit");
ClearB = new JButton("Clear");

pane.add(HeadingLabel);
pane.add(FilerLabel);
pane.add(NameLabel);
pane.add(NameText);
pane.add(ISBNLabel);
pane.add(IsbnText);
pane.add(PriceLabel);
pane.add(PriceText);
pane.add(Author1Label);
pane.add(Author1Text);
pane.add(Author2Label);
pane.add(Author2Text);
pane.add(Author3Label);
pane.add(Author3Text);
pane.add(Author4Label);
pane.add(Author4Text);
pane.add(QuantityLabel);
pane.add(QuantityText);
pane.add(PublisherLabel);
pane.add(PublisherText);
pane.add(YearOfPublicationLabel);
pane.add(YearOfPublicationText);
pane.add(SubmitB);
pane.add(ClearB);

setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);

}
});

MemberAction.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e ) {


Container pane = getContentPane();
pane.setLayout(new GridLayout(7,2));

HeadingLabelM = new JLabel("Enter Customer Info.");
FilerLabelM = new JLabel("Filer Label");
MemberNameM = new JLabel("Customer Name");
MemberIdM = new JLabel("Member ID");
NumberBookbought = new JLabel("Number of Books Bought.");
AmountSpent = new JLabel("Amount Spent");
MemberShip = new JLabel("Membership:");
NameTextM = new JTextField("");
MemberIdText = new JTextField("");
NumberBookboughtText = new JTextField("");
AmountSpentText = new JTextField("");
MemberShipText = new JTextField("");
SubmitBM = new JButton("Submit");
ClearBM = new JButton("Clear");

pane.add(HeadingLabelM);
pane.add(FilerLabelM);
pane.add(MemberNameM);
pane.add(MemberIdM);
pane.add(NumberBookbought);
pane.add(AmountSpentText);
pane.add(MemberShipText);
pane.add(NameText);
pane.add(MemberIdText);
pane.add(NumberBookboughtText);
pane.add(AmountSpentText);
pane.add(MemberShipText);
pane.add(SubmitBM);
pane.add(ClearBM);

setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);





}

});




}

public static void main (String[] args)
{

BookStoreProgram StoreP = new BookStoreProgram();

StoreP.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
StoreP.setVisible(true);
}







}
[Message sent by forum member 'zamouri' (zamouri)]

http://forums.java.net/jive/thread.jspa?messageID=342610