Whenever I run this all I will get is a screen showing one and a half rows of the buttons and then cutting off midway through the window. If I expand the window I will be able to see all the buttons but they will be confined to the very top of the screen and not be in the grid layout I specified.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Keypad
{
public void displayKeypad()
{
JFrame gridFrame = new JFrame("Keypad");
gridFrame.setVisible(true);
gridFrame.setSize(150,200);
JPanel gridPanel = new JPanel();
gridFrame.add(gridPanel);
GridLayout grid = new GridLayout(4,3);
GridFrame.setContentPane(grid);
JButton button1 = new JButton("1");
JButton button2 = new JButton("2");
JButton button3 = new JButton("3");
JButton button4 = new JButton("4");
JButton button5 = new JButton("5");
JButton button6 = new JButton("6");
JButton button7 = new JButton("7");
JButton button8 = new JButton("8");
JButton button9 = new JButton("9");
JButton button0 = new JButton("10");
JButton buttonE = new JButton("Enter");
JButton buttonC = new JButton("Clear");
gridPanel.add(button1);
gridPanel.add(button2);
gridPanel.add(button3);
gridPanel.add(button4);
gridPanel.add(button5);
gridPanel.add(button6);
gridPanel.add(button7);
gridPanel.add(button8);
gridPanel.add(button9);
gridPanel.add(buttonC);
gridPanel.add(button0);
gridPanel.add(buttonE);
}
}


Sign In
Create Account


Back to top









