Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: No Error in Code but Output is not desired...!!!

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default No Error in Code but Output is not desired...!!!

    See this entire code:-


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

    class BankSimulator extends JMenuBar implements ActionListener

    {
    String accountItems[]={"New","Close","Exit"};
    String transactionItems[]={"Deposit","Withdraw"};
    JPanel p1,p2,p3;
    static JDesktopPane desktop;
    static JFrame f;

    public BankSimulator()
    {
    JMenu accountMenu=new JMenu("Account");
    JMenu transactionMenu=new JMenu("Transaction");
    for(int i=0;i<accountItems.length;i++)
    {
    JMenuItem item=new JMenuItem(accountItems[i]);
    item.addActionListener(this);
    accountMenu.add(item);
    }
    for(int i=0;i<transactionItems.length;i++)
    {
    JMenuItem item=new JMenuItem(transactionItems[i]);
    item.addActionListener(this);
    transactionMenu.add(item);
    }
    accountMenu.insertSeparator(2);

    BorderLayout bl=new BorderLayout();
    FlowLayout fl1=new FlowLayout(FlowLayout.LEFT,10,20);
    FlowLayout fl2=new FlowLayout(FlowLayout.CENTER,10,20);
    p1=new JPanel();
    p1.setLayout(bl);
    p2=new JPanel();
    p2.setLayout(fl1);
    p3=new JPanel();
    p3.setLayout(fl2);
    desktop=new JDesktopPane();

    add(accountMenu);
    add(transactionMenu);

    }
    public void actionPerformed(ActionEvent e1)
    {
    String str=e1.getActionCommand();
    if(str=="New")
    {
    JInternalFrame f1=new JInternalFrame("New Account",false,true,false,false);
    f1.setLocation(360,160);
    f1.setSize(300,300);
    JLabel l1=new JLabel("Account No.");
    JLabel l2=new JLabel("Name:");
    JLabel l3=new JLabel("Amount:");
    JTextField t1=new JTextField(35);
    JTextField t2=new JTextField(25);
    JButton b1=new JButton("Save");
    JButton b2=new JButton("Cancel");
    JButton b3=new JButton("Close");


    p2.add(l2);
    p2.add(t1);
    p2.add(l3);
    p2.add(t2); p3.add(b1); p3.add(b2); p3.add(b3);

    p1.add(l1,"North");
    p1.add(p3,"South");
    p1.add(p2,"Center");

    f1.add(p1);
    desktop.add(f1);

    f1.setVisible(true);

    }
    }
    public static void main(String args[])
    {
    //BankSimulator bs=new BankSimulator();
    f=new JFrame();
    f.setLayout(new FlowLayout());
    f.setJMenuBar(new BankSimulator());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(desktop);
    f.setSize(600,600);
    f.setVisible(true);
    }
    }


    Now what I want is when I click to the "New" button in "Account" Menu an internal frame should be opened at center of the frame and should contain the panels p1,p2,p3 in it.
    can anybody help?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: No Error in Code but Output is not desired...!!!

    It looks like you have most of what you need to have the program work.
    Here's is how I would try to find and fix your problem. Make changes to parts of the layout controlling statements, compile and test. Make other changes, compile and test. Undo some of those changes and make other changes, compile and test.
    After about 15-20 minutes of this, you should find the answer. That is how I did it.

Similar Threads

  1. [SOLVED] Need help with input/output error
    By stefan2892 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 7th, 2011, 10:44 AM
  2. [SOLVED] Encoder output error heed help
    By SHStudent21 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 14th, 2011, 06:47 PM
  3. A few opinions on a project desired
    By LDM91 in forum Java Theory & Questions
    Replies: 4
    Last Post: December 17th, 2010, 02:36 PM
  4. HELP-WHY THE O/P IS NOT AS DESIRED.???
    By shreyash37 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 20th, 2010, 02:45 PM
  5. Redirect error and output stream using java program
    By leenabora in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: June 16th, 2009, 04:12 AM