Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-28-2007, 06:42 PM
Senior Member
 
Join Date: Jun 2007
Posts: 119
Peter is on a distinguished road
JavaBean Problem
This code doesn't work, can you check it and then tell me the problem?

Code:
import java.util.*; public class NumberEvent extends EventObject{ public int number1, number2; public NumberEvent(Object o, int number1, int number2) { super(o); this.number1=number1; this.number2=number2; } } 2/ import java.util.*; public interface NumberEnteredListener extends EventListener{ public void arithmeticPerformed(NumberEvent mec); } 3/ this code I used NetBeans IDE 5.0 to make import java.io.Serializable; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; public class NumberBean extends javax.swing.JPanel implements ActionListener, Serializable{ public NumberBean() { initComponents(); } NumberEnteredListener me1; public void addNumberListener(NumberEnteredListener me1){ this.me1=me1; } NumberEvent mec; public void fireNumberEvent(NumberEvent mec){ me1.arithmeticPerformed(mec); } public void actionPerformed(ActionEvent ae){ if(ae.getSource()==ok){ int f1=Integer.parseInt(tf1.getText()); int f2=Integer.parseInt(tf2.getText()); mec=new NumberEvent(ok, f1, f2); fireNumberEvent(mec); } } 4/ import javax.swing.*; public class ArithmeticPerformer extends JFrame implements NumberEnteredListener{ NumberBean meb; /** Creates a new instance of ArithmeticPerformer */ public ArithmeticPerformer() { super("Arithmetic Caculations"); meb=new NumberBean(); getContentPane().add(meb); meb.addNumberListener(this); } public void arithmeticPerformed(NumberEvent mec){ int result=mec.number1+mec.number2; String temp="The result of adding the numbers is : " + String.valueOf(result); JOptionPane.showMessageDialog(this, temp); } public static void main(String arg[]){ ArithmeticPerformer mec=new ArithmeticPerformer(); mec.setSize(300, 300); mec.setVisible(true); } }
I can start the UI but the calculation can not operate (The JOptionPane does not appear.).

Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-05-2007, 03:21 PM
Ed Ed is offline
Senior Member
 
Join Date: Jun 2007
Posts: 110
Ed is on a distinguished road
Peter:
you forgot to call ok.addActionListener
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-05-2007, 03:37 PM
Ed Ed is offline
Senior Member
 
Join Date: Jun 2007
Posts: 110
Ed is on a distinguished road
I think that connection object is in null
check it
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 04:42 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org