| | |
Calculator using JFrame help
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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:
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)
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * Calculator.java * * Created on Sep 7, 2009, 3:19:12 PM */ package calculator; import java.awt.*; import javax.swing.*; /** * * @author William */ public class Calculator extends javax.swing.JFrame { /** Creates new form Calculator */ public Calculator() { this.setLayout(new BorderLayout()); JLabel lbl = new JLabel("Calculator"); JTextField tf = new JTextField(30); tf.setBackground(Color.yellow); JPanel p1 = new JPanel(); p1.setLayout(new BorderLayout()); p1.add(lbl, BorderLayout.NORTH); p1.add(tf, BorderLayout.SOUTH); JButton b1 = new JButton("1"); JButton b2 = new JButton("2"); JButton b3 = new JButton("3"); JButton b4 = new JButton("4"); JButton b5 = new JButton("5"); JButton b6 = new JButton("6"); JButton b7 = new JButton("7"); JButton b8 = new JButton("8"); JButton b9 = new JButton("9"); JButton b10 = new JButton("#"); JButton b11 = new JButton("0"); JButton b12 = new JButton("*"); JButton b13 = new JButton("+"); JButton b14 = new JButton("-"); JButton b15 = new JButton("x"); JButton b16 = new JButton("/"); JPanel p2 = new JPanel(new FlowLayout()); p2.add(b7); p2.add(b8); p2.add(b9); p2.add(b13); p2.add(b4); p2.add(b5); p2.add(b6); p2.add(b14); p2.add(b1); p2.add(b2); p2.add(b3); p2.add(b15); p2.add(b10); p2.add(b11); p2.add(b12); p2.add(b16); this.add(p1, BorderLayout.CENTER); this.add(p2, BorderLayout.CENTER); this.setTitle("Calculator"); this.setVisible(true); }
•
•
Join Date: Jan 2008
Posts: 3,832
Reputation:
Solved Threads: 501
This is a perfect candidate for a 4 x 4 GridLayout.
http://java.sun.com/docs/books/tutor...yout/grid.html
http://java.sun.com/javase/6/docs/ap...ridLayout.html
http://java.sun.com/docs/books/tutor...yout/grid.html
http://java.sun.com/javase/6/docs/ap...ridLayout.html
![]() |
Similar Threads
- Need help for MDAS rules in a Calculator. (Java)
- isFixReg() ??? (Java)
- Fraction Calculator (Java)
- need help with my java calculator (Java)
- Java Swing Calculator program not running. It has 0 errors (Java)
- Calculator GUI (Java)
- calculator --- using more than 2 operands? (Java)
- simple calculator help (Java)
Other Threads in the Java Forum
- Previous Thread: Mysql+ play sound
- Next Thread: Understanding some SQLite Java Wrapper code
| Thread Tools | Search this Thread |
Tag cloud for Calculator using JFrame help - gridlayout







