-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHFrame.java
48 lines (37 loc) · 1.04 KB
/
HFrame.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class HFrame extends JFrame
{
public HFrame(int x)
{
//creates the frame with the given
//title
super("Tower of Hanoi");
//makes the x kill program
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//makes the window not able to be resized by user
setResizable(false);
//creates the window
pack();
//creates panel
HPanel p=new HPanel(x);
//gets the frames insets
//the size of title bar and framing is insets
Insets in = getInsets();
//calculates the size needed
//for the frame and its panel
int frameWidth=p.getWidth()+in.left+in.right;
int frameHeight=p.getHeight()+in.top+in.bottom;
//sets the desired siZe for frame
setPreferredSize(new Dimension(frameWidth, frameHeight));
//turns off the layout options
setLayout(null);
//add the panel to the frame
add(p);
//adjust the size ogf the frame to the preferredSize
pack();
//make the frame visible
setVisible(true);
}
}