Member Avatar for Nichan
Nichan

hi all

the purpose of this simple codes is to show a text in a text box when i click the button. Both are on in different panel and then placed in one main panel with box layout...

actually, i made it a simple case...
still, the prob still exists...

please help...
i provide you the code. One for panel with button, and one for panel with textbox...
my friend said that nothing wrong with my code but still, it didn't work out...she is as confused as i am...

just don't change the idea of 2 panel, ok?...make it still what it was...
it seems simple, but it didn't work out...if i understand this case, i'm sure i can understand what the bound property is and how to use it...


==========================================================

code 1:


import javax.swing.*;
import java.awt.event.*;
//import java.awt.*;
import java.beans.*;
import java.io.Serializable;

public class Loan2 extends JPanel implements ActionListener{

JButton b;

protected PropertyChangeSupport chg=new PropertyChangeSupport(this);
private String start="";

public Loan2(){
b=new JButton("Show Word");

add(b);

b.addActionListener(this);

setSize(400,400);
setVisible(true);

}

public void setWord(String news){
String old=new String();
old=start;

try{
chg.firePropertyChange("ShowWord",old,news);
}
catch(Exception e){
System.out.println("Exception: "+e);
}
start=news;
}

public String getWord(){
return start;
}


public void actionPerformed(ActionEvent ae){
if(ae.getSource()==b){
setWord("It's your personal Loan!");
}
}

public void addPropertyListener(PropertyChangeListener pcl){
chg.addPropertyChangeListener(pcl);
}

public void removePropertyListener(PropertyChangeListener pcl){
chg.removePropertyChangeListener(pcl);
}
}


code2:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.io.*;


public class CustomerLoan2 extends JFrame implements PropertyChangeListener{


JPanel panel;
JPanel main;
JTextField tf;
BoxLayout bl;


public CustomerLoan2(){

setTitle("Loan Frame");
panel=new JPanel();
main=new JPanel();
tf=new JTextField(10);

Loan2 l2=new Loan2();

bl=new BoxLayout(main,BoxLayout.Y_AXIS);
bl.addLayoutComponent(new String("Loan 2"),l2);
bl.addLayoutComponent(new String("Customer Loan 2"),panel);


getContentPane().add(main);
panel.add(tf);

System.out.println(1);
main.add(l2);
main.add(panel);

System.out.println(2);
l2.addPropertyChangeListener(this);

setSize(400,400);
setVisible(true);

}
public void propertyChange(PropertyChangeEvent pce){
System.out.println(3);
String newTransferred=pce.getNewValue().toString();
System.out.println(4);
tf.setText(newTransferred);

}

public static void main(String[] a){
CustomerLoan2 cl2=new CustomerLoan2();
}


}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.