Calculator using JFrame help

Thread Solved

Join Date: Oct 2008
Posts: 60
Reputation: Whilliam is an unknown quantity at this point 
Solved Threads: 0
Whilliam's Avatar
Whilliam Whilliam is offline Offline
Junior Poster in Training

Calculator using JFrame help

 
0
  #1
Sep 8th, 2009
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:
  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. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,819
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Calculator using JFrame help

 
1
  #2
Sep 8th, 2009
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 60
Reputation: Whilliam is an unknown quantity at this point 
Solved Threads: 0
Whilliam's Avatar
Whilliam Whilliam is offline Offline
Junior Poster in Training

Re: Calculator using JFrame help

 
0
  #3
Sep 8th, 2009
thanks so much. ^_^
Reply With Quote Quick reply to this message  
Reply

Tags
gridlayout

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC