0

i get no GUI when i run!

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


public class Calculator
{
private JTextField resultTF;
private JButton calculateB, numbersB[] = new JButton[11];



public void driver()
{
//Create Window
JFrame calc = new JFrame("Calculator version 1.0");
calc.setSize(500, 500);
calc.setDefaultCloseOperation(calc.EXIT_ON_CLOSE);


//Get the content pane (object of type Container)
Container cp = calc.getContentPane();
cp.setLayout(new GridLayout(4, 3));


resultTF = new JTextField(10);


resultTF.setEditable(false);


numbersB[0] = new JButton("clear");
String num;
for(int i = 1; i<11; i++)
{
numbersB = new JButton();
numbersB.setText(Integer.toString(i-1));
}


calc.setVisible(true);


Calculator c = new Calculator();
c.driver();
}


public static void main(String[]args){
new Calculator();
}



}

Edited by Nick Evan: Fixed formatting

2
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by JamesCherrill
0

sorry i clicked the minus, i havent used this forum... what do you mean???

You create buttons etc but you don't add them to your JFrame.

1

You need to add your buttons etc to the form, otherwize they are just floating about in a vacuum. Eg

Container cp = calc.getContentPane();
...
resultTF = new JTextField(10);
[B]cp.add(resultTF);[/B]
0

well i did just that and Still no gui popup

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

public class Calculator
{
	private JTextField resultTF;
	private JButton calculateB, numbersB[] = new JButton[11];


	public void driver()
	{
	//Create Window
	JFrame calc = new JFrame("Calculator version 1.0");
	calc.setSize(500, 500);
	calc.setDefaultCloseOperation(calc.EXIT_ON_CLOSE);

	//Get the content pane (object of type Container)
	Container cp = calc.getContentPane();
	cp.setLayout(new GridLayout(4, 3));

	resultTF = new JTextField(10);

	resultTF.setEditable(false);

	numbersB[0] = new JButton("clear");
	String num;
	for(int i = 1; i<11; i++)
	{
		numbersB[i] = new JButton();
		numbersB[i].setText(Integer.toString(i-1));
	}



	Calculator c = new Calculator();
	c.driver();

	cp.add(resultTF);
	for (int i=0; i<11; i++)
		{
		cp.add(numbersB[i]);
		}

	calc.setVisible(true);
	}

	public static void main(String[]args){
		new Calculator();
	}


}

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.