By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,346 Members | 2,331 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,346 IT Pros & Developers. It's quick & easy.

Java - Calculator GUI woes

P: 2
Hi, ive been looking for a solid java community to help me when im tearing out my hair :)

Basically ive constructed a GUI that has to represent the same look and functions of the typical windows calculator.

Ive made 4 classes 2 do this, my reasoning so it was easier to look through( when programming) rather than getting mixed up in my own code!

My questions and problems:
Ive been messing around with the windows look and feel, somethign seems a little off about it...have i did somethign wrong?

As you can see from my code ive only made the actual GUI, i dont have a clue how to add functionality to the buttons. Im not here asking for one of you to do everything, is it possible someone could explain how id go about this? OR give a small example? (even if it was an example for one of the buttons id bebale to understand and work through it again :))

I prob realise theres much better ways to go this program than the wya i have done it, but atleast im trying :)




Expand|Select|Wrap|Line Numbers
  1.  
  2. import javax.swing.*;
  3. import java.awt.*;
  4.  
  5. // The look and feel stuff, still to fix
  6. import javax.swing.plaf.metal.MetalLookAndFeel;
  7. import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
  8.  
  9. class CalcFrame extends JFrame
  10.     {
  11.         /* Main Panels */
  12.         viewPanel tp;
  13.         calcPanel1 bp1;
  14.         calcPanel2 bp2;
  15.  
  16.         /** menu  **/
  17.         JMenuBar jmb;
  18.         JMenu jmi1,jmi2,jmi3;
  19.         CalcFrame()
  20.         {
  21.             super("Calculator");
  22.             Container cp = getContentPane();
  23.             cp.setLayout(new FlowLayout());
  24.  
  25.             cp.setBackground(new Color(241,237,222) );
  26.             tp = new viewPanel();
  27.             bp1  = new calcPanel1();
  28.             bp2 = new calcPanel2();
  29.             cp.add(tp);
  30.             cp.add(bp1);
  31.             cp.add(bp2);
  32.  
  33.             /** Menu (top bar) **/
  34.             jmb = new JMenuBar();
  35.             jmb.setBackground(new Color(241,237,222));
  36.             jmi1 = new JMenu("Edit",true);
  37.             jmi1.setBackground(new Color(241,237,222));
  38.             jmi2 = new JMenu("View",true);
  39.             jmi2.setBackground(new Color(241,237,222));
  40.             jmi3 = new JMenu("Help",true);
  41.             jmi3.setBackground(new Color(241,237,222));
  42.             jmb.add(jmi1);
  43.             jmb.add(jmi2);
  44.             jmb.add(jmi3);
  45.             this.setJMenuBar(jmb);
  46.  
  47.             this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  48.             this.setSize(340,320);
  49.  
  50.              // Twtf, fix this...doesnt look right :S 
  51.             try
  52.                 {
  53.                     UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
  54.                 }
  55.             catch(Exception cnfe)
  56.                 {
  57.                     System.out.println("Error, Error, Error'");
  58.                 }
  59.  
  60.             SwingUtilities.updateComponentTreeUI(getContentPane());
  61.  
  62.  
  63.             setVisible(true);
  64.             setResizable(false);
  65.  
  66.         }
  67.  
  68.         public static void main(String args[])
  69.         {
  70.             CalcFrame cf = new CalcFrame();
  71.         }
  72.  
  73.  
  74.     }
  75.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. import javax.swing.*;
  3. import java.awt.*;
  4.  
  5.  
  6. class calcPanel1 extends JPanel
  7.     {
  8.         JButton blank, BackSpace, CE, C;
  9.  
  10.         calcPanel1()
  11.         {
  12.             Color buttons_color = new Color(242,244,241);
  13.             Color background_color = new Color(241,237,222);
  14.             blank = new JButton("    ");
  15.             blank.setDefaultCapable(false);
  16.             blank.setBackground(buttons_color);
  17.             blank.setEnabled(false);
  18.             blank.setMargin(new Insets(6,7,6,7));
  19.             add(blank);
  20.             BackSpace = new JButton("BackSpace");
  21.             BackSpace.setForeground(Color.red);
  22.             BackSpace.setBackground(buttons_color);
  23.             BackSpace.setMargin(new Insets(6,4,6,4));
  24.             add(BackSpace);
  25.             CE = new JButton("CE");
  26.             CE.setForeground(Color.red);
  27.             CE.setBackground(buttons_color);
  28.             CE.setMargin(new Insets(6,29,6,29));
  29.             add(CE);
  30.             C = new JButton("C");
  31.             C.setForeground(Color.red);
  32.             C.setBackground(buttons_color);
  33.             C.setMargin(new Insets(6,29,6,29));
  34.  
  35.             add(C);
  36.             setBackground(background_color);
  37.  
  38.         }
  39.  
  40.         public static void main(String args[])
  41.         {
  42.             JFrame tester = new JFrame("Calculator");
  43.             Container  c  = tester.getContentPane();
  44.             calcPanel1 t = new calcPanel1();
  45.             c.add(t);
  46.             tester.setSize(300,300);
  47.             tester.setVisible(true);
  48.         }
  49.     }
  50.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. import javax.swing.*;
  3. import java.awt.*;
  4.  
  5.  
  6.  
  7. class calcPanel2 extends JPanel
  8.     {
  9.         JButton MC, MR, MS, MPlus;
  10.         JButton  Slash, Star, Minus, Plus, Sqrt, Percent, Reciprocal,Equals, PlusMinus,Point;
  11.         JButton []digits;
  12.  
  13.  
  14.         calcPanel2()
  15.         {
  16.             setupButtons();
  17.             Color background_color = new Color(241,237,222);
  18.             setBackground(background_color);
  19.             setLayout(new GridLayout(4,6,5,5));
  20.  
  21.             // row 1
  22.             this.add(MC);
  23.             this.add(digits[7]);
  24.             this.add(digits[8]);
  25.             this.add(digits[9]);
  26.             this.add(Slash);
  27.             this.add(Sqrt);
  28.             // row 2
  29.             this.add(MR);
  30.             this.add(digits[4]);
  31.             this.add(digits[5]);
  32.             this.add(digits[6]);
  33.             this.add(Star);
  34.             this.add(Percent);
  35.             // row 3
  36.             this.add(MS);
  37.             this.add(digits[1]);
  38.             this.add(digits[2]);
  39.             this.add(digits[3]);
  40.             this.add(Minus);
  41.             this.add(Reciprocal);
  42.             //row 4
  43.             this.add(MPlus);
  44.             this.add(digits[0]);
  45.             this.add(PlusMinus);
  46.             this.add(Point);
  47.             this.add(Plus);
  48.             this.add(Equals);
  49.  
  50.         }
  51.  
  52.         public static void main(String args[])
  53.         {
  54.             JFrame tester = new JFrame("Calculator");
  55.             Container  c  = tester.getContentPane();
  56.             calcPanel2 t = new calcPanel2();
  57.             c.add(t);
  58.             tester.setSize(300,300);
  59.             tester.setVisible(true);
  60.         }
  61.  
  62.         public void setupButtons()
  63.         {
  64.             Color buttons_color = new Color(242,244,241);
  65.             Insets buttonMargin = new Insets(5,1,5,1);
  66.             // set up Mem Clear
  67.             MC = new JButton("MC");
  68.             MC.setBackground(buttons_color);
  69.             MC.setForeground(Color.red);
  70.             MC.setMargin(buttonMargin);
  71.  
  72.             // set up Mem Recall
  73.             MR = new JButton("MR");
  74.             MR.setBackground(buttons_color);
  75.             MR.setForeground(Color.red);
  76.             MR.setMargin(buttonMargin);
  77.  
  78.             // Set up Mem Store
  79.             MS = new JButton("MS");
  80.             MS.setBackground(buttons_color);
  81.             MS.setForeground(Color.red);
  82.             MS.setMargin(buttonMargin);
  83.  
  84.             //Set up Mem +
  85.             MPlus = new JButton("M+");
  86.             MPlus.setBackground(buttons_color);
  87.             MPlus.setForeground(Color.red);
  88.             MS.setMargin(buttonMargin);
  89.  
  90.             // Set up /
  91.             Slash = new JButton("/");
  92.             Slash.setBackground(buttons_color);
  93.             Slash.setForeground(Color.red);
  94.             Slash.setMargin(buttonMargin);
  95.  
  96.             // Set up *
  97.             Star = new JButton("*");
  98.             Star.setBackground(buttons_color);
  99.             Star.setForeground(Color.red);
  100.             Star.setMargin(buttonMargin);
  101.  
  102.             // Set up -
  103.             Minus = new JButton("-");
  104.             Minus.setBackground(buttons_color);
  105.             Minus.setForeground(Color.red);
  106.             Minus.setMargin(buttonMargin);
  107.  
  108.             // Set up +
  109.             Plus = new JButton("+");
  110.             Plus.setBackground(buttons_color);
  111.             Plus.setForeground(Color.red);
  112.             Plus.setMargin(buttonMargin);
  113.  
  114.             // Set up sqrt
  115.             Sqrt = new JButton("sqrt");
  116.             Sqrt.setBackground(buttons_color);
  117.             Sqrt.setForeground(Color.blue);
  118.             Sqrt.setMargin(buttonMargin);
  119.  
  120.             // Set up %
  121.             Percent = new JButton("%");
  122.             Percent.setBackground(buttons_color);
  123.             Percent.setForeground(Color.blue);
  124.             Percent.setMargin(buttonMargin);
  125.  
  126.             // Set up Reci
  127.             Reciprocal = new JButton("1/x");
  128.             Reciprocal.setBackground(buttons_color);
  129.             Reciprocal.setForeground(Color.blue);
  130.             Reciprocal.setMargin(buttonMargin);
  131.  
  132.             // Set up =
  133.             Equals = new JButton("=");
  134.             Equals.setBackground(buttons_color);
  135.             Equals.setForeground(Color.red);
  136.             Equals.setMargin(buttonMargin);
  137.  
  138.             // Set up .
  139.             Point = new JButton(".");
  140.             Point.setBackground(buttons_color);
  141.             Point.setForeground(Color.red);
  142.             Point.setMargin(buttonMargin);
  143.  
  144.             // Set up +/-
  145.             PlusMinus = new JButton("+/-");
  146.             PlusMinus.setBackground(buttons_color);
  147.             PlusMinus.setForeground(Color.blue);
  148.             PlusMinus.setMargin(buttonMargin);
  149.  
  150.             digits = new JButton[10];
  151.  
  152.             for (int i=0;i<10;i++)
  153.                 {
  154.                     digits[i] = new JButton(""+i);
  155.                     digits[i].setBackground(buttons_color);
  156.                     digits[i].setForeground(Color.blue);
  157.                     digits[i].setMargin(buttonMargin);
  158.                 }
  159.  
  160.         }
  161.     }
  162.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import javax.swing.plaf.metal.MetalLookAndFeel;
  5. import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
  6.  
  7. class viewPanel extends JPanel
  8.     {
  9.         JTextField output;
  10.  
  11.         viewPanel()
  12.         {
  13.             output = new JTextField("0",28);
  14.             output.setFont(new Font("Courier", Font.PLAIN, 16));
  15.             // Align text to the right.
  16.             output.setHorizontalAlignment(4);
  17.             this.add(output);
  18.             Color background_color = new Color(241,237,222);
  19.             this.setBackground(background_color);
  20.         }
  21.  
  22.         public static void main(String args[])
  23.         {
  24.             // change so it looks better
  25.  
  26.             JFrame tester = new JFrame("Calculator");
  27.             Container  c  = tester.getContentPane();
  28.             textPanel t = new textPanel();
  29.             c.add(t);
  30.             tester.setSize(300,300);
  31.             tester.setVisible(true);
  32.         }
  33.     }
  34.  
Thanks for reading
Kind regards
Bob
Mar 23 '06 #1
Share this Question
Share on Google+
3 Replies


P: 1
Here it is the same thing as you did, but much simplier .... also the functionality isn't implemented (action performed on each tiny little button) ...

import java.awt.*;
import javax.swing.*;

/**
* @author Sorinel CRISTESCU
*/
public class SccCalculator extends JPanel {

JTextField output;

public SccCalculator () {
super (new GridBagLayout());

// first line ... the digits ...
GridBagConstraints c = new GridBagConstraints ();
c.gridx = 0;
c.gridy = 0;
c.ipadx = 6;
c.ipady = 6;
c.gridwidth = 7;
c.weightx = 100;
c.insets = new Insets (3,3,3,3);
c.fill = c.HORIZONTAL;

output = new JTextField("0");
output.setFont(new Font("Courier", Font.PLAIN, 14));
output.setHorizontalAlignment(SwingConstants.RIGHT );
this.add(output, c);

// second line ... NOBUTTON, Backspace, CE & C buttons
c.gridwidth = 1;
c.gridy = 1;
c.weightx = 1;
c.fill = c.NONE;
JButton nobut = new JButton(" ");
nobut.setBorder(BorderFactory.createEmptyBorder()) ;
nobut.setEnabled(false);
this.add(nobut, c);

c.gridx = 1;
c.gridwidth = 2;
c.weightx = 30;
c.fill = c.HORIZONTAL;
JButton backspace = new JButton("Backspace");
backspace.setForeground(Color.red);
this.add(backspace, c);

c.gridx = 3;
c.gridwidth = 1;
JButton ce = new JButton("CE");
ce.setForeground(Color.red);
this.add(ce, c);

c.gridx = 4;
c.gridwidth = 2;
JButton clear = new JButton("C");
clear.setForeground(Color.red);
this.add(clear, c);

// third line MC, 7, 8, 9, /, sqrt
c.gridy = 2;
c.gridx = 0;
c.gridwidth = 1;
c.weightx = 1;

JButton mc = new JButton("MC");
mc.setForeground(Color.red);
this.add(mc, c);
nobut.setPreferredSize(mc.getPreferredSize());

c.gridx = 1;
JButton seven = new JButton("7");
seven.setForeground(Color.blue);
this.add(seven, c);

c.gridx = 2;
JButton eight = new JButton("8");
eight.setForeground(Color.blue);
this.add(eight, c);

c.gridx = 3;
JButton nine = new JButton("9");
nine.setForeground(Color.blue);
this.add(nine, c);

c.gridx = 4;
JButton divide = new JButton("/");
divide.setForeground(Color.red);
this.add(divide, c);

c.gridx = 5;
JButton sqrt = new JButton("sqrt");
sqrt.setForeground(Color.blue);
this.add(sqrt, c);

// forth line MR, 4, 5, 6, *, %
c.gridy = 3;
c.gridx = 0;

JButton mr = new JButton("MR");
mr.setForeground(Color.red);
this.add(mr, c);

c.gridx = 1;
JButton four = new JButton("4");
four.setForeground(Color.blue);
this.add(four, c);

c.gridx = 2;
JButton five = new JButton("5");
five.setForeground(Color.blue);
this.add(five, c);

c.gridx = 3;
JButton six = new JButton("6");
six.setForeground(Color.blue);
this.add(six, c);

c.gridx = 4;
JButton multiply = new JButton("*");
multiply.setForeground(Color.red);
this.add(multiply, c);

c.gridx = 5;
JButton procent = new JButton("%");
procent.setForeground(Color.blue);
this.add(procent, c);

// fifth line MS, 1, 2, 3, ., +, =
c.gridy = 4;
c.gridx = 0;

JButton ms = new JButton("MS");
ms.setForeground(Color.red);
this.add(ms, c);

c.gridx = 1;
JButton one = new JButton("1");
one.setForeground(Color.blue);
this.add(one, c);

c.gridx = 2;
JButton two = new JButton("2");
two.setForeground(Color.blue);
this.add(two, c);

c.gridx = 3;
JButton three = new JButton("3");
three.setForeground(Color.blue);
this.add(three, c);

c.gridx = 4;
JButton minus = new JButton("-");
minus.setForeground(Color.red);
this.add(minus, c);

c.gridx = 5;
JButton divideby = new JButton("1/x");
divideby.setForeground(Color.blue);
this.add(divideby, c);

// sixth line M+, 0, +/-, ., +, =
c.gridy = 5;
c.gridx = 0;

JButton mplus = new JButton("M+");
mplus.setForeground(Color.red);
this.add(mplus, c);

c.gridx = 1;
JButton zero = new JButton("0");
zero.setForeground(Color.blue);
this.add(zero, c);

c.gridx = 2;
JButton plusminus = new JButton("+/-");
plusminus.setForeground(Color.blue);
this.add(plusminus, c);

c.gridx = 3;
JButton dot = new JButton(".");
dot.setForeground(Color.blue);
this.add(dot, c);

c.gridx = 4;
JButton plus = new JButton("+");
plus.setForeground(Color.red);
this.add(plus, c);

c.gridx = 5;
JButton egal = new JButton("=");
egal.setForeground(Color.blue);
this.add(egal, c);

}

/**
* @param args
*/
public static void main(String[] args) {
// try {
// UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
// } catch (Exception cnfe) {
// System.out.println("Error, Error, Error'");
// }

SccCalculator panel = new SccCalculator ();
JDialog dlg = new JDialog ();
dlg.setTitle("Simple Calculator");
dlg.getContentPane().add (panel);
dlg.pack();
dlg.setModal(true);
dlg.setResizable(false);
dlg.setVisible(true);
System.exit(0);
}

}
Feb 13 '07 #2

hirak1984
100+
P: 316
well sample action listener for buttons 7,8,9 is added.

rest do yourself by implementing logic.
Different actionlistener for each button is also possible.
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import javax.swing.*;
  5. /**
  6. * @author Sorinel CRISTESCU
  7. */
  8. public class SccCalculator extends JPanel implements ActionListener {
  9. JTextField output;
  10. public SccCalculator () {
  11. super (new GridBagLayout());
  12. // first line ... the digits ...
  13. GridBagConstraints c = new GridBagConstraints ();
  14. c.gridx = 0;
  15. c.gridy = 0;
  16. c.ipadx = 6;
  17. c.ipady = 6;
  18. c.gridwidth = 7;
  19. c.weightx = 100;
  20. c.insets = new Insets (3,3,3,3);
  21. c.fill = c.HORIZONTAL;
  22. output = new JTextField("0");
  23. output.setFont(new Font("Courier", Font.PLAIN, 14));
  24. output.setHorizontalAlignment(SwingConstants.RIGHT );
  25. this.add(output, c);
  26. // second line ... NOBUTTON, Backspace, CE & C buttons
  27. c.gridwidth = 1;
  28. c.gridy = 1;
  29. c.weightx = 1;
  30. c.fill = c.NONE;
  31. JButton nobut = new JButton(" ");
  32. nobut.setBorder(BorderFactory.createEmptyBorder()) ;
  33. nobut.setEnabled(false);
  34. this.add(nobut, c);
  35. c.gridx = 1;
  36. c.gridwidth = 2;
  37. c.weightx = 30;
  38. c.fill = c.HORIZONTAL;
  39. JButton backspace = new JButton("Backspace");
  40. backspace.setForeground(Color.red);
  41. this.add(backspace, c);
  42. c.gridx = 3;
  43. c.gridwidth = 1;
  44. JButton ce = new JButton("CE");
  45. ce.setForeground(Color.red);
  46. this.add(ce, c);
  47. c.gridx = 4;
  48. c.gridwidth = 2;
  49. JButton clear = new JButton("C");
  50. clear.setForeground(Color.red);
  51. this.add(clear, c);
  52. // third line MC, 7, 8, 9, /, sqrt
  53. c.gridy = 2;
  54. c.gridx = 0;
  55. c.gridwidth = 1;
  56. c.weightx = 1;
  57. JButton mc = new JButton("MC");
  58. mc.setForeground(Color.red);
  59. this.add(mc, c);
  60. nobut.setPreferredSize(mc.getPreferredSize());
  61. c.gridx = 1;
  62. JButton seven = new JButton("7");
  63. seven.setForeground(Color.blue);
  64. seven.setActionCommand("7");
  65. seven.addActionListener(this);
  66. this.add(seven, c);
  67. c.gridx = 2;
  68. JButton eight = new JButton("8");
  69. eight.setForeground(Color.blue);
  70. eight.setActionCommand("8");
  71. eight.addActionListener(this);
  72. this.add(eight, c);
  73. c.gridx = 3;
  74. JButton nine = new JButton("9");
  75. nine.setForeground(Color.blue);
  76. nine.setActionCommand("9");
  77. nine.addActionListener(this);
  78. this.add(nine, c);
  79. c.gridx = 4;
  80. JButton divide = new JButton("/");
  81. divide.setForeground(Color.red);
  82. this.add(divide, c);
  83. c.gridx = 5;
  84. JButton sqrt = new JButton("sqrt");
  85. sqrt.setForeground(Color.blue);
  86. this.add(sqrt, c);
  87. // forth line MR, 4, 5, 6, *, %
  88. c.gridy = 3;
  89. c.gridx = 0;
  90. JButton mr = new JButton("MR");
  91. mr.setForeground(Color.red);
  92. this.add(mr, c);
  93. c.gridx = 1;
  94. JButton four = new JButton("4");
  95. four.setForeground(Color.blue);
  96. this.add(four, c);
  97. c.gridx = 2;
  98. JButton five = new JButton("5");
  99. five.setForeground(Color.blue);
  100. this.add(five, c);
  101. c.gridx = 3;
  102. JButton six = new JButton("6");
  103. six.setForeground(Color.blue);
  104. this.add(six, c);
  105. c.gridx = 4;
  106. JButton multiply = new JButton("*");
  107. multiply.setForeground(Color.red);
  108. this.add(multiply, c);
  109. c.gridx = 5;
  110. JButton procent = new JButton("%");
  111. procent.setForeground(Color.blue);
  112. this.add(procent, c);
  113. // fifth line MS, 1, 2, 3, ., +, =
  114. c.gridy = 4;
  115. c.gridx = 0;
  116. JButton ms = new JButton("MS");
  117. ms.setForeground(Color.red);
  118. this.add(ms, c);
  119. c.gridx = 1;
  120. JButton one = new JButton("1");
  121. one.setForeground(Color.blue);
  122. this.add(one, c);
  123. c.gridx = 2;
  124. JButton two = new JButton("2");
  125. two.setForeground(Color.blue);
  126. this.add(two, c);
  127. c.gridx = 3;
  128. JButton three = new JButton("3");
  129. three.setForeground(Color.blue);
  130. this.add(three, c);
  131. c.gridx = 4;
  132. JButton minus = new JButton("-");
  133. minus.setForeground(Color.red);
  134. this.add(minus, c);
  135. c.gridx = 5;
  136. JButton divideby = new JButton("1/x");
  137. divideby.setForeground(Color.blue);
  138. this.add(divideby, c);
  139. // sixth line M+, 0, +/-, ., +, = 
  140. c.gridy = 5;
  141. c.gridx = 0;
  142. JButton mplus = new JButton("M+");
  143. mplus.setForeground(Color.red);
  144. this.add(mplus, c);
  145. c.gridx = 1;
  146. JButton zero = new JButton("0");
  147. zero.setForeground(Color.blue);
  148. this.add(zero, c);
  149. c.gridx = 2;
  150. JButton plusminus = new JButton("+/-");
  151. plusminus.setForeground(Color.blue);
  152. this.add(plusminus, c);
  153. c.gridx = 3;
  154. JButton dot = new JButton(".");
  155. dot.setForeground(Color.blue);
  156. this.add(dot, c);
  157. c.gridx = 4;
  158. JButton plus = new JButton("+");
  159. plus.setForeground(Color.red);
  160. this.add(plus, c);
  161. c.gridx = 5;
  162. JButton egal = new JButton("=");
  163. egal.setForeground(Color.blue);
  164. this.add(egal, c);
  165. }
  166. /**
  167. * @param args
  168. */
  169. public static void main(String[] args) {
  170. // try {
  171. // UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
  172. // } catch (Exception cnfe) {
  173. // System.out.println("Error, Error, Error'");
  174. // }
  175. SccCalculator panel = new SccCalculator ();
  176. JDialog dlg = new JDialog ();
  177. dlg.setTitle("Simple Calculator");
  178. dlg.getContentPane().add (panel);
  179. dlg.pack();
  180. dlg.setModal(true);
  181. dlg.setResizable(false);
  182. dlg.setVisible(true);
  183. System.exit(0);
  184. }
  185. public void actionPerformed(ActionEvent ae) {
  186.  // TODO Auto-generated method stub
  187.  String comm=ae.getActionCommand();
  188.  //String count[]=new String[2];
  189.  if(comm=="7")
  190.  {
  191.  output.setText(comm);
  192.  }
  193.  if(comm=="8")
  194.  {
  195.  output.setText(comm);
  196.  }
  197.  if(comm=="9")
  198.  {
  199.  output.setText(comm);
  200.  }
  201. }
  202. }
  203.  
Feb 13 '07 #3

10K+
P: 13,264
Now that's some thread digging.
Feb 13 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.