943,531 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 2908
  • Java RSS
Sep 8th, 2009
0

Calculator using JFrame help

Expand Post »
Hello. I'm trying to make a calculator with JFrame. I'm only gonna make the appearance of the calculator (not functioning). The numbers and operators are supposed to be arranged this way:

7 8 9 +
4 5 6 -
1 2 3 x
# 0 * /

however, I only know borderlayout and flowlayout. Is there any layout or anything that will make the operators and number arranged that way (above)?

I've made a java code. Here it is:
java Syntax (Toggle Plain Text)
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. /*
  7.  * Calculator.java
  8.  *
  9.  * Created on Sep 7, 2009, 3:19:12 PM
  10.  */
  11.  
  12. package calculator;
  13.  
  14. import java.awt.*;
  15. import javax.swing.*;
  16. /**
  17.  *
  18.  * @author William
  19.  */
  20. public class Calculator extends javax.swing.JFrame {
  21.  
  22. /** Creates new form Calculator */
  23. public Calculator() {
  24.  
  25. this.setLayout(new BorderLayout());
  26. JLabel lbl = new JLabel("Calculator");
  27.  
  28. JTextField tf = new JTextField(30);
  29. tf.setBackground(Color.yellow);
  30.  
  31. JPanel p1 = new JPanel();
  32. p1.setLayout(new BorderLayout());
  33. p1.add(lbl, BorderLayout.NORTH);
  34. p1.add(tf, BorderLayout.SOUTH);
  35.  
  36. JButton b1 = new JButton("1");
  37. JButton b2 = new JButton("2");
  38. JButton b3 = new JButton("3");
  39. JButton b4 = new JButton("4");
  40. JButton b5 = new JButton("5");
  41. JButton b6 = new JButton("6");
  42. JButton b7 = new JButton("7");
  43. JButton b8 = new JButton("8");
  44. JButton b9 = new JButton("9");
  45. JButton b10 = new JButton("#");
  46. JButton b11 = new JButton("0");
  47. JButton b12 = new JButton("*");
  48. JButton b13 = new JButton("+");
  49. JButton b14 = new JButton("-");
  50. JButton b15 = new JButton("x");
  51. JButton b16 = new JButton("/");
  52.  
  53. JPanel p2 = new JPanel(new FlowLayout());
  54.  
  55. p2.add(b7);
  56. p2.add(b8);
  57. p2.add(b9);
  58. p2.add(b13);
  59. p2.add(b4);
  60. p2.add(b5);
  61. p2.add(b6);
  62. p2.add(b14);
  63. p2.add(b1);
  64. p2.add(b2);
  65. p2.add(b3);
  66. p2.add(b15);
  67. p2.add(b10);
  68. p2.add(b11);
  69. p2.add(b12);
  70. p2.add(b16);
  71.  
  72. this.add(p1, BorderLayout.CENTER);
  73. this.add(p2, BorderLayout.CENTER);
  74.  
  75. this.setTitle("Calculator");
  76. this.setVisible(true);
  77.  
  78.  
  79.  
  80.  
  81. }
Similar Threads
Reputation Points: 19
Solved Threads: 0
Junior Poster
Whilliam is offline Offline
110 posts
since Oct 2008
Sep 8th, 2009
1

Re: Calculator using JFrame help

Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,371 posts
since Jan 2008
Sep 8th, 2009
0

Re: Calculator using JFrame help

thanks so much. ^_^
Reputation Points: 19
Solved Threads: 0
Junior Poster
Whilliam is offline Offline
110 posts
since Oct 2008

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: Mysql+ play sound
Next Thread in Java Forum Timeline: Understanding some SQLite Java Wrapper code





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


Follow us on Twitter


© 2011 DaniWeb® LLC