This code, when run, will make a window but not at the specified dimensions. What is wrong with it?
import javax.swing.*;
import java.awt.*;
public class Windowing {
void JFrame(){
JFrame frames = new JFrame("Total recall");
frames.setSize(1000,8000);
frames.setVisible(true);
frames.pack();
//Buttons push = new Buttons();
//((Buttons) push).buttons();
JTextField wager = new JTextField(1);
wager.setSize(100,200);
wager.setVisible(true);
wager.setLocation(100, 200);
frames.add(wager);
//frames.add(push);
}
}
It looks like you have a number of “opportunity areas” here.
To start, it seems like you set frame size to 1000×8000 because you didn’t see any change right?
Secondly you call
setVisibleon the textField because you didn’t see that either.And finally you’re setting the size of the textfield ( I guess because you’re seeing it take the whole frame )
The problem here is that you have to invoke
packandsetVisibleat the end of the construction. Also, you have to learn how to use layout managers and frames.Swing, is very powerful, but it is a bit hard to grasp at the beginning.
These two links will be helpful:
How to make frames
Using Layout Managers
I’ve changed your code and the result looks like this:
Here’s the modified source code.