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
text [2] [i] from panel [1] is invisible
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
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class TellerWindow extends JFrame{
public static void main (String []r ) {
new TellerWindow();
}
Graphics g;
Customer[] customer;
Button [] operateb = {new Button("Show customer information"),new Button ("Create a new customer"),new Button("Change customer data")};
Panel panel[] = { new Panel(),new Panel(),new Panel(),new Panel()};
TextField text[][] = new TextField [3][];
ActionListener b1 = new ActionListener() {
public void actionPerformed ( ActionEvent e) {
if(e.getSource() == operateb[0]){
panel[2].setVisible(false);
panel[3].setVisible(false);
panel[1].setVisible(true);
g = panel[1].getGraphics();
drawp1();
}
}
};
ActionListener b2 = new ActionListener() {
public void actionPerformed ( ActionEvent e) {
if(e.getSource() == operateb[1]){
panel[1].setVisible(false);
panel[3].setVisible(false);
panel[2].setVisible(true);
g = panel[2].getGraphics();
drawp2();
}
}
};
{
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
setLayout(new FlowLayout());
setSize(400,600);
setLocation(30,20);
setLayout(null);
setVisible(true);
for( int i =1;i <4;i++) {
panel[i].setSize(400,400);
panel[i].setVisible(false);
panel[i].setLocation(0,200);
}
panel[0].setSize(400,200);
panel[0].setLocation(0,0);
// panel[0].setBackground(Color.black);
panel[0].setVisible(true);
for(int i = 0 ; i<4; i++) {
panel[i].setLayout(new SpringLayout ());
add(panel[i]);
}
panel[0].setLayout(null);
panel[1].setLayout(null);
for (int i = 0 ;i <3; ++i) {
operateb[i].setSize(175,25);
operateb[i].setVisible(true);
panel[0].add(operateb[i]);operateb[i].setLocation(113,(i+1)*40-20);
}
text[0] = new TextField [10];
for (int i=0; i < 10; i++) {
text[0][i] = new TextField ();
text[0][i].setColumns(40);
text[0][i].setLocation(10,(i + 1) *35);
text[0][i].setVisible(true);
panel[1].add(text[0][i]);
}
text[0][0].setText("Customer ID :");
text[0][1].setText("Customer Name :");
text[0][2].setText("Customer date of birth:");
text[0][3].setText("Customer Address:");
text[0][4].setText("Customer City:");
text[0][5].setText("Customer Street:");
text[0][6].setText("Customer phone :");
text[0][7].setText("Customer email:");
text[0][8].setText("Customer zip:");
text[1] = new TextField [10];
text[2] = new TextField [10];
for (int i = 0 ;i <10 ; i++) {
text[1][i] = new TextField ();
text[1][i].setText(text[0][i].getText());
text[2][i] = new TextField ();
text[1][i].setLocation(10,(i+1)*35);
text[2][i].setLocation(10,(i+1)*35);
text[1][i].setVisible(true);
text[2][i].setVisible(true);
text[2][i].setColumns(40);
panel[2].add(text[1][i]);
panel[3].add(text[2][i]);
}
for (int i = 0 ; i<10; i ++ )
text[0][i].setEditable(false);
operateb[0].addActionListener(b1);
operateb[1].addActionListener(b2);
// operateb[2].addActionListener(b3);
}
/* void createCustomer () {
for (int i ; i<20; i++ )
if(customer [i] == null) {
customer[i] = new Customer ();
customer[i].setID(i + 1);
break;
}
}
*/
private void createCustomer ( String fname, String lname, java.util.Date DOB) {
for (int i = 0 ; i < 20; i++ )
if(customer [i] == null) {
customer[i] = new Customer (fname, lname, DOB,i+1);
break;
}
}
private void drawp1 () {
for(int i =0;i <10; ++i)
g.drawString(text[0][i].getText(),20,(i+1)*35);
}
private void drawp2 () {
for(int i = 0 ; i <10 ; i++)
// g.drawString(text[1][i].getText(),40,(i+1)*35 - 15);
}
}
Code:
for(int i = 0 ; i<4; i++) {
panel[i].setLayout(new SpringLayout ());
add(panel[i]);
}
// and
text[1] = new TextField [10];
text[2] = new TextField [10];
for (int i = 0 ;i <10 ; i++) {
text[1][i] = new TextField ();
text[1][i].setText(text[0][i].getText());
text[2][i] = new TextField ();
text[1][i].setLocation(10,(i+1)*35);
text[2][i].setLocation(10,(i+1)*35);
text[1][i].setVisible(true);
text[2][i].setVisible(true);
text[2][i].setColumns(40);
panel[2].add(text[1][i]);
panel[3].add(text[2][i]);
}
Comment