ElJosh ElJosh - 1 month ago 6x
Java Question

JFrame not showing up after running

I am working a JFrame calculator, I am not to familiar with so I was following a tutorial, and I've double checked it a couple times.
It's not working, its not throwing any errors or anything, it will compile and run. Just nothing pops up.
I am using Eclipse, and it is giving two warnings,
one about my constructor not being used in my main
that my class says this: The serializable class Gui does not declare a static final serialVersionUID field of type long.

I'm not sure why those would come up, but my code seems to be like the tutorial.

Thank you in advanced.

Ps. excuse the all commons, I just making sure I can looking back at it without having to refer back to the tutorial.

// This will make the visuals of the calc

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class Gui extends JFrame implements ActionListener {

JPanel[] row = new JPanel[5];
JButton[] button = new JButton[19];

String[] buttonString = {"7", "8", "9", "+", // This is a string for the buttons that we will later apply to
"4", "5", "6", "-", // the the buttons with a loop, instead of 19 lines for each one
"1", "2", "3", "*",
".", "/", "C", "√",
"-/+", "=", "0"};

int[] dimW = {300, 45, 100, 90}; // An Array for the different widths of the display and buttons
int[] dimH = {35, 40}; // An array for the different heights of the display and buttons

Dimension displayDimension = new Dimension(dimW[0], dimH[0]); // The dims for the display using the first ints of the arrays
Dimension regularDimension = new Dimension(dimW[1], dimH[1]); // The
Dimension rColumnDimension = new Dimension(dimW[2], dimH[1]);
Dimension zeroButDimension = new Dimension(dimW[3], dimH[1]);

Boolean[] function = new Boolean[4]; // A boolean array to tell, which operator we are using

double[] temp = {0, 0}; // A temp array for the calc, might not use when using my stack calc

JTextArea display = new JTextArea(1, 20); // This is the display where the text will be displayed

Font font = new Font("Ariel", Font.BOLD, 14);

Gui() {


setSize(380, 250); // Set the frame size
setResizable(false); // Makes so it can't be resized, can mess up layout if it true
setDefaultCloseOperation(EXIT_ON_CLOSE); // What happens when it closes

GridLayout grid = new GridLayout(5, 5); // Since we need a grid of 5 by 5 for the buttons this makes the grid

for (int i = 0; i < 4; i++) // Sets values for the function array, might use might not with my clac
function[i] = false;

FlowLayout f1 = new FlowLayout(FlowLayout.CENTER); // This will only be use to layout row 1
FlowLayout f2 = new FlowLayout(FlowLayout.CENTER, 1, 1); // The ints are used to give a 1 pt gap vert and horiztal

for (int i = 0; i < 5; i++) // Intinalizing the Jpanel row's so we can use them
row[i] = new JPanel();

row[0].setLayout(f1); // Since we need the first row to have the special layout of f1 we just assign it

for (int i = 1; i < 5; i++) // Since we already set the first row "Row[0]" to f1, we have to start with row 2 or row[1] for i

// After this all the rows have the correct layout, we can set up the buttons
// And set the same thing to each button with a loop
for (int i = 0; i < 19; i++) {

button[i] = new JButton(); // Creates a new button for each button in the array
button[i].setText(buttonString[1]); // Sets text on the button with the text from the list, in ButtonString
button[i].setFont(font); // Makes it nice looking with the fancy font we used in the font line
button[i].addActionListener(this); // This is what makes the button actually work

// Buttons done we can move to the display set up
display.setFont(font); // Set the fancy font to the display too
display.setEditable(false); // Makes it so no input from the keyboard, will have to change this on final product
display.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); // Makes it pop in right to left

// With the fonts and everything intinlized we can start to set the sizes for the compents
display.setPreferredSize(displayDimension); // Sets the size of the display

// We can use a loop for the regular buttons, i think all but zero
for (int i = 0; i < 14; i++) {
button[i].setPreferredSize(regularDimension); // Sets the size of the regular buttons
for (int i = 14; i < 18; i++) {
button[i].setPreferredSize(rColumnDimension); // Sets the size of the right column of buttons, the operrantors
button[18].setPreferredSize(zeroButDimension); // Sets the size of the zero button since its bigger

// Now that we got evrything sized up time to add everything to the panel
row[0].add(display); // Adds the display to row 1
add(row[0]); // Adds row 1 to the panel

for (int i = 0; i < 4; i++) {
row[1].add(button[i]); // all the number buttons to the row
row[1].add(button[14]); // adds the operator button to the row
add(row[1]); // adds the row

for (int i = 4; i < 8; i++) {
row[2].add(button[i]); // all the number buttons to the row
row[2].add(button[15]); // adds the operator button to the row
add(row[2]); // adds the row

for (int i = 8; i < 12; i++) {
row[3].add(button[i]); // all the number buttons to the row
row[3].add(button[16]); // adds the operator button to the row
add(row[3]); // adds the row

for (int i = 12; i < 14; i++) {
row[4].add(button[i]); // all the number buttons to the row
row[4].add(button[17]); // adds the operator button to the row
add(row[4]); // adds the row

setVisible(true); // Makes so you can see it


// Not sure what this is
public final void setDesign() {
try {

} catch (Exception e) {

// Will be use to make actionlistener work
public void actionPerformed(ActionEvent ae) {


public void main(String[] arguments) {
Gui c = new Gui();


You should really have this in your main method

public static void main(String[] args){
Gui c = new Gui();