By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,352 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,352 IT Pros & Developers. It's quick & easy.

layout manager problem

P: 14
hello,

my program is a simple banking application, i need it for my resumee, but i have a little problem
i got stuck trying to maek some TextField -s visible , it seems that setting the layout ( null or SpringLayout ) even if i setVisible ( true ) , the text fields will not become visible pls help

this is my code
if u do not want to read all the code i wrote again at the end just the part that i am iterrested about

Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. class TellerWindow extends JFrame{
  6.  
  7.     public static void main (String []r ) {
  8.  
  9.         new TellerWindow();
  10.     }
  11.  
  12.     Graphics g;
  13.  
  14.     Customer[] customer;
  15.  
  16.     Button [] operateb = {new Button("Show customer information"),new Button ("Create a new customer"),new Button("Change customer data")};
  17.  
  18.     Panel panel[] = { new Panel(),new Panel(),new Panel(),new Panel()};
  19.  
  20.     TextField text[][] = new TextField [3][];
  21.  
  22.     ActionListener b1 = new ActionListener() {
  23.         public void actionPerformed ( ActionEvent e) {
  24.             if(e.getSource() == operateb[0]){
  25.                 panel[2].setVisible(false);
  26.                 panel[3].setVisible(false);
  27.                 panel[1].setVisible(true);
  28.                     g = panel[1].getGraphics();
  29.                 drawp1();
  30.             }
  31.  
  32.         }
  33.     };
  34.  
  35.     ActionListener b2 = new ActionListener() {
  36.         public void actionPerformed ( ActionEvent e) {
  37.             if(e.getSource() == operateb[1]){
  38.                 panel[1].setVisible(false);
  39.                 panel[3].setVisible(false);
  40.                 panel[2].setVisible(true);
  41.                  g = panel[2].getGraphics();
  42.                 drawp2();
  43.             }
  44.  
  45.         }
  46.     };
  47.  
  48.     {
  49.  
  50.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  51.         setLayout(null);
  52.         setLayout(new FlowLayout());
  53.  
  54.         setSize(400,600);
  55.         setLocation(30,20);
  56.            setLayout(null);
  57.         setVisible(true);
  58.  
  59.         for( int i =1;i <4;i++) {
  60.             panel[i].setSize(400,400);
  61.             panel[i].setVisible(false);
  62.             panel[i].setLocation(0,200);
  63.         }
  64.  
  65.         panel[0].setSize(400,200);
  66.         panel[0].setLocation(0,0);
  67.      //    panel[0].setBackground(Color.black);
  68.         panel[0].setVisible(true);
  69.  
  70.         for(int i = 0 ; i<4; i++) {
  71.             panel[i].setLayout(new SpringLayout ());
  72.             add(panel[i]);
  73.         }
  74.  
  75.         panel[0].setLayout(null);
  76.         panel[1].setLayout(null);
  77.  
  78.         for (int i = 0 ;i <3; ++i) {
  79.             operateb[i].setSize(175,25);
  80.  
  81.             operateb[i].setVisible(true);
  82.             panel[0].add(operateb[i]);operateb[i].setLocation(113,(i+1)*40-20);
  83.         }
  84.  
  85.         text[0] = new TextField [10];
  86.  
  87.         for (int i=0; i < 10; i++) {
  88.             text[0][i] = new TextField ();  
  89.  
  90.             text[0][i].setColumns(40);
  91.             text[0][i].setLocation(10,(i + 1) *35);
  92.             text[0][i].setVisible(true);
  93.             panel[1].add(text[0][i]);
  94.         }
  95.  
  96.         text[0][0].setText("Customer ID :");
  97.         text[0][1].setText("Customer Name :");
  98.         text[0][2].setText("Customer date of birth:");
  99.         text[0][3].setText("Customer Address:");
  100.         text[0][4].setText("Customer City:");
  101.         text[0][5].setText("Customer Street:");
  102.         text[0][6].setText("Customer phone :");
  103.         text[0][7].setText("Customer email:");
  104.         text[0][8].setText("Customer zip:");
  105.  
  106.         text[1] = new TextField [10];
  107.         text[2] = new TextField [10];
  108.  
  109.         for (int i = 0 ;i <10 ; i++) {
  110.             text[1][i] = new TextField ();
  111.             text[1][i].setText(text[0][i].getText());
  112.             text[2][i] = new TextField ();
  113.  
  114.             text[1][i].setLocation(10,(i+1)*35);
  115.             text[2][i].setLocation(10,(i+1)*35);
  116.             text[1][i].setVisible(true);
  117.             text[2][i].setVisible(true);
  118.             text[2][i].setColumns(40);
  119.  
  120.             panel[2].add(text[1][i]);
  121.             panel[3].add(text[2][i]);
  122.  
  123.         }
  124.  
  125.         for (int i = 0 ; i<10; i ++ )
  126.             text[0][i].setEditable(false);
  127.  
  128.         operateb[0].addActionListener(b1);
  129.         operateb[1].addActionListener(b2);
  130. //        operateb[2].addActionListener(b3);
  131.  
  132.  
  133.  
  134.     }
  135.  
  136.  
  137.  
  138. /*    void createCustomer () {
  139.         for (int i ; i<20; i++ )
  140.             if(customer [i] == null) {
  141.                 customer[i] = new Customer ();
  142.                 customer[i].setID(i + 1);
  143.                 break;
  144.             }
  145.     }
  146. */
  147.     private void createCustomer ( String fname, String lname, java.util.Date DOB) {
  148.  
  149.         for (int i = 0 ; i < 20; i++ )
  150.             if(customer [i] == null) {
  151.                 customer[i] = new Customer (fname, lname, DOB,i+1);
  152.                 break;
  153.             }
  154.     }
  155.  
  156.     private void drawp1 () {
  157.  
  158.         for(int i =0;i <10; ++i)
  159.             g.drawString(text[0][i].getText(),20,(i+1)*35);
  160.     }
  161.  
  162.     private void drawp2 () {
  163.  
  164.         for(int i = 0 ; i <10 ; i++)
  165.         //    g.drawString(text[1][i].getText(),40,(i+1)*35 - 15); 
  166.     }
  167. }
text [2] [i] from panel [1] is invisible

Expand|Select|Wrap|Line Numbers
  1.     for(int i = 0 ; i<4; i++) {
  2.             panel[i].setLayout(new SpringLayout ());
  3.             add(panel[i]);
  4.         }
  5.  
  6.                 //   and 
  7.  
  8.     text[1] = new TextField [10];
  9.         text[2] = new TextField [10];
  10.  
  11.         for (int i = 0 ;i <10 ; i++) {
  12.             text[1][i] = new TextField ();
  13.             text[1][i].setText(text[0][i].getText());
  14.             text[2][i] = new TextField ();
  15.  
  16.             text[1][i].setLocation(10,(i+1)*35);
  17.             text[2][i].setLocation(10,(i+1)*35);
  18.             text[1][i].setVisible(true);
  19.             text[2][i].setVisible(true);
  20.             text[2][i].setColumns(40);
  21.  
  22.             panel[2].add(text[1][i]);
  23.             panel[3].add(text[2][i]);
  24.  
  25.         }
May 14 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 10K+
P: 11,448
hello,

my program is a simple banking application, i need it for my resumee, but i have a little problem
i got stuck trying to maek some TextField -s visible , it seems that setting the layout ( null or SpringLayout ) even if i setVisible ( true ) , the text fields will not become visible pls help
I didn't read all that code; is the problem *some* of those text fields or are *all*
of the text fields invisible?

btw never set a LayoutManager to null.

kind regards,

Jos
May 14 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.