Hello there
I'm creating a calculator, but I'm stuck at the GUI. My problem is, i want to add the JPanel "Buttons" to the JFrame in the class "Panel".
The thought was, that "Buttons" would represent a 3x3 matrix of buttons.
"Buttons" should then be added to "Panel" together with "textWindow" in a borderLayout. The GUI is not working the way i want it to, and is not displaying anything.
Class Panel
package gui; import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; public final class Panel extends JFrame { private static final long serialVersionUID = 1L; public static final Panel frame = new Panel(); public Panel() { super(); setTitle("Calculator"); setLayout(new BorderLayout()); this.setJMenuBar(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setContentPane(new MainPanel()); this.setVisible(true); this.pack(); this.setLocationRelativeTo(null); } private class MainPanel extends JPanel { private static final long serialVersionUID = 1L; public MainPanel() { super(new BorderLayout()); JTextField text = new JTextField(10); JPanel textWindow = new JPanel(); textWindow.add(text); this.add(textWindow, BorderLayout.NORTH); this.add(Buttons.panel, BorderLayout.SOUTH); } } }
Class Buttons
package gui; import java.awt.GridLayout; import javax.swing.JPanel; import javax.swing.JButton; public class Buttons extends JPanel { private static final long serialVersionUID = 1L; public static final Buttons panel = new Buttons(); public Buttons() { super(new GridLayout(3,3)); this.add(new JButton("1")); this.add(new JButton("2")); this.add(new JButton("3")); this.add(new JButton("4")); this.add(new JButton("5")); this.add(new JButton("6")); this.add(new JButton("7")); this.add(new JButton("8")); this.add(new JButton("9")); } }
Class Main
[/CODE]import gui.Panel; public class Main { public static void main (String [] _) { new Panel(); } }