Hey there pretty new to GUI java programming, my task is to create a calculator, im just having trouble with the actual layout of the calculator so far it is supposed to have a text box then below the buttons of the calculator and below this another text box, but all i can seem to do is create one grid which isn't adequate, this is my code, please help!
import javax.swing.*; import java.awt.*; import java.awt.event.*; class BlackFrame extends JFrame { JTextField box1, box2; JButton Zero, C, Exclemation, Equals, One, Two, Three, Multiply, Four, Five, Six, Minus, Seven, Eight, Nine, Plus; // GUI components // State of calculator public BlackFrame () { JFrame frame = new JFrame("Black (DC)"); frame.setSize(200, 250); frame.setVisible(true); JPanel a = new JPanel(); frame.add(a); a.setVisible(true); JPanel b = new JPanel(); frame.add(b); b.setVisible(true); JPanel c = new JPanel(); frame.add(c); c.setVisible(true); box1 = new JTextField (10); a.add(box1); c.setLayout(new GridLayout(4, 1)); Zero = new JButton("0"); c.add(Zero); C = new JButton("C"); c.add(C); Exclemation = new JButton("!"); c.add(Exclemation); Equals = new JButton("="); c.add(Equals); One = new JButton("1"); c.add(One); Two = new JButton("2"); c.add(Two); Three = new JButton("3"); c.add(Three); Multiply = new JButton("*"); c.add(Multiply); Four = new JButton("4"); c.add(Four); Five = new JButton("5"); c.add(Five); Six = new JButton("6"); c.add(Six); Minus = new JButton("-"); c.add(Minus); Seven = new JButton("7"); c.add(Seven); Eight = new JButton("8"); c.add(Eight); Nine = new JButton("9"); c.add(Nine); Plus = new JButton("+"); c.add(Plus); box2 = new JTextField (10); b.add(box2); setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); } }
Edit/Delete Message