943,752 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 1946
  • Java RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Dec 19th, 2007
0

Re: isFixReg() ???

Nicely explained, darkagn.

Quote ...
Inside the Calculation function where dReg1 is passed to where does this dReg1 orginate from? Could dReg1 here be passed from the code section below it(refer code below). I doubt it. Then in that case, how does dReg1 go into Calculation at all?Notice it's: dReg1 = Calculation(sOperator, dReg1, dReg2); Having dReg1 as both result and argument is confusing.
Why not? Remember this much. In any assignment expression, the RHS is evaluated first and then the result is stored in LHS.

Hope this makes it clear..
Reputation Points: 193
Solved Threads: 25
Posting Pro
Jishnu is offline Offline
518 posts
since Oct 2006
Dec 19th, 2007
0

Re: isFixReg() ???

Hi darkagn,

Thanks. It's now clear to me.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nljavaingineur is offline Offline
15 posts
since Nov 2007
Dec 29th, 2007
0

A problem with calculator code

Hello,

I have the code below done in JBuilder for a calculator. Unlike the previous code I've posted which uses an MVC structure, this one does not. For instance while creating a button, it is "Button button1= new Button(); " instead of "pKey.add(new Button("C")); "(refer to previous post where the code's written by T.Yamazaki). I very much would like to create my code in JBuilder using the same structure in T.Yamazakii's code, where each key that is clicked is handled through its event handlers. How do I overcome this problem? Any suggestion is welcomed.

<code>
package assign1;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import java.awt.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/

public class Frame1 extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
TextField textField1 = new TextField();
Button button1 = new Button();
Button button2 = new Button();
Button button3 = new Button();
Button button4 = new Button();
Button button5 = new Button();
Button button6 = new Button();
Button button7 = new Button();
Button button8 = new Button();
Button button9 = new Button();
Button button10 = new Button();
Button button11 = new Button();
Button button12 = new Button();
Button button13 = new Button();
Button button14 = new Button();
Button button15 = new Button();
Button button16 = new Button();

//selfmade attributes
int number1, number2,number3;
String operator;

public Frame1() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}

/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(xYLayout1);
setSize(new Dimension(400, 300));
setTitle("Calculator");
textField1.setText("");
button1.setLabel("1");
button1.addActionListener(new Frame1_button1_actionAdapter(this));
button2.setLabel("+");
button2.addActionListener(new Frame1_button2_actionAdapter(this));
button3.setLabel("=");
button3.addActionListener(new Frame1_button3_actionAdapter(this));
button4.setLabel("4");
button4.addActionListener(new Frame1_button4_actionAdapter(this));
button5.setLabel("2");
button5.addActionListener(new Frame1_button5_actionAdapter(this));
button6.setLabel("3");
button6.addActionListener(new Frame1_button6_actionAdapter(this));
button7.setLabel("5");
button7.addActionListener(new Frame1_button7_actionAdapter(this));
button8.setLabel("6");
button8.addActionListener(new Frame1_button8_actionAdapter(this));
button9.setLabel("7");
button9.addActionListener(new Frame1_button9_actionAdapter(this));
button10.setLabel("8");
button10.addActionListener(new Frame1_button10_actionAdapter(this));
button11.setLabel("9");
button11.addActionListener(new Frame1_button11_actionAdapter(this));
button12.setLabel("/");
button13.setLabel("*");
button14.setLabel("-");
button15.setLabel("0");
button15.addActionListener(new Frame1_button15_actionAdapter(this));
button16.setLabel(".");
contentPane.add(textField1, new XYConstraints(14, 19, 366, 54));
contentPane.add(button9, new XYConstraints(179, 84, 41, 28));
contentPane.add(button10, new XYConstraints(227, 85, 47, 28));
contentPane.add(button8, new XYConstraints(227, 118, 48, 33));
contentPane.add(button7, new XYConstraints(179, 118, 42, 34));
contentPane.add(button1, new XYConstraints(179, 157, 46, 33));
contentPane.add(button14, new XYConstraints(335, 155, 45, 33));
contentPane.add(button15, new XYConstraints(180, 194, 44, 35));
contentPane.add(button6, new XYConstraints(279, 156, 49, 34));
contentPane.add(button4, new XYConstraints(280, 119, 47, 34));
contentPane.add(button11, new XYConstraints(279, 84, 50, 30));
contentPane.add(button13, new XYConstraints(335, 119, 44, 31));
contentPane.add(button12, new XYConstraints(335, 86, 43, 29));
contentPane.add(button5, new XYConstraints(229, 157, 45, 34));
contentPane.add(button2, new XYConstraints(279, 194, 47, 33));
contentPane.add(button3, new XYConstraints(336, 192, 43, 35));
contentPane.add(button16, new XYConstraints(235, 198, 40, 30));
}

public void button1_actionPerformed(ActionEvent e) {
String help;
help = textField1.getText();
textField1.setText(help+"1");
}

public void button5_actionPerformed(ActionEvent e) {
String help;
help = textField1.getText();
textField1.setText(help+"2");

}

public void button6_actionPerformed(ActionEvent e) {
String help;
help = textField1.getText();
textField1.setText(help+"3");
}

public void button4_actionPerformed(ActionEvent e) {
String help;
help = textField1.getText();
textField1.setText(help+"4");
}

public void button7_actionPerformed(ActionEvent e) {
String help;
help = textField1.getText();
textField1.setText(help+"5");
}

public void button8_actionPerformed(ActionEvent e) {
String help;
help = textField1.getText();
textField1.setText(help+"6");
}

public void button9_actionPerformed(ActionEvent e) {
String help;
help = textField1.getText();
textField1.setText(help+"7");
}

public void button10_actionPerformed(ActionEvent e) {
String help;
help = textField1.getText();
textField1.setText(help+"8");
}

public void button11_actionPerformed(ActionEvent e) {
String help;
help = textField1.getText();
textField1.setText(help+"9");
}

public void button15_actionPerformed(ActionEvent e) {
String help;
help = textField1.getText();
textField1.setText(help+"0");
}

public void button2_actionPerformed(ActionEvent e) {
String help;
help = textField1.getText();
number1 = Integer.parseInt(help);
textField1.setText("");
operator = "+";

}

public void button3_actionPerformed(ActionEvent e) {
String help;
help = textField1.getText();
number2 = Integer.parseInt(help);
String si = String.valueOf(number1+number2);
textField1.setText(si);
}


class Frame1_button3_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_button3_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.button3_actionPerformed(e);
}
}


class Frame1_button2_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_button2_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.button2_actionPerformed(e);
}
}


class Frame1_button15_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_button15_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.button15_actionPerformed(e);
}
}


class Frame1_button11_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_button11_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.button11_actionPerformed(e);
}
}


class Frame1_button10_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_button10_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.button10_actionPerformed(e);
}
}


class Frame1_button9_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_button9_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.button9_actionPerformed(e);
}
}


class Frame1_button8_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_button8_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.button8_actionPerformed(e);
}
}


class Frame1_button7_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_button7_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.button7_actionPerformed(e);
}
}


class Frame1_button4_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_button4_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.button4_actionPerformed(e);
}
}


class Frame1_button6_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_button6_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.button6_actionPerformed(e);
}
}


class Frame1_button5_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_button5_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.button5_actionPerformed(e);
}
}


class Frame1_button1_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_button1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.button1_actionPerformed(e);
}
}
}

</code>

Thank you.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nljavaingineur is offline Offline
15 posts
since Nov 2007
Dec 30th, 2007
1

Re: isFixReg() ???

Hi nljavaingineur, I suggest you these things:

-Start a new thread for a new problem. It is related to this thread but you are using a different approach.
-Use code tags.
-Use proper alignment in code.
Reputation Points: 193
Solved Threads: 25
Posting Pro
Jishnu is offline Offline
518 posts
since Oct 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Components
Next Thread in Java Forum Timeline: i need help with GUI





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC