| | |
beans bound property: getNewValue() doesn't work out. Code attached
![]() |
•
•
Join Date: Sep 2004
Posts: 2
Reputation:
Solved Threads: 0
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();
}
}
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();
}
}
![]() |
Similar Threads
- String array problem (C++)
- JSF HTTP 500 error (JSP)
- inserting code in css stylesheet (HTML and CSS)
- VB6 Building Access from code (Visual Basic 4 / 5 / 6)
- Void* Array - HELP! (C)
- LCD C code problems (C++)
- Please anyone help tweak my code The code tags are around it now (Java)
- Please anyone help tweak my code (Java)
- TopMost property doesn't work (VB.NET)
Other Threads in the Java Forum
- Previous Thread: JMF question: question about the unrealized player
- Next Thread: Printing in Java
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card class client code collision component crashcourse css csv database eclipse ee error fractal free ftp game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linked linux list loan machine map method methods migrate mobile netbeans objects oriented output phone physics printf problem program programming project projects radio recursion replaydirector reporting researchinmotion rotatetext scanner se server service set sms software sort sql string swing test textfield threads tree trolltech ubuntu utility windows





