- #1
Chrono
- 425
- 2
Ok, guys, I need some help here. This was done using Java, by the way. One of the homework questions we had a while ago was to create a frame and within the frame create two panels and on the two panels create three buttons using BorderLayout. Here's what I had:
import javax.swing.*;
import java.awt.*;
public class NO1HW2 extends JFrame
{
public void ShowBorderLayout()
{
Container mycontainer = getContentPane();
mycontainer.setLayout(new BorderLayout(10,10));
JPanel p1 = new JPanel();
for(int i = 1; i <= 3; i++)
p1.add(new JButton("Button " + i));
JPanel p2 = new JPanel();
for(int i = 4; i <= 6; i++)
p2.add(new JButton("Button " + i));
mycontainer.add(p1, BorderLayout.CENTER);
mycontainer.add(p2, BorderLayout.SOUTH);
}
public static void main(String args[])
{
NO1HW2 frame = new NO1HW2();
frame.setTitle("Show BorderLayout");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setVisible(true);
}
}
When I run the program the frame will pop up but that's it. The panels or buttons won't show. I asked my professor what the problem was and after making sure I set the frame visible to true he didn't know what else was wrong. Do y'all see anything that can cause it to not show the buttons?
import javax.swing.*;
import java.awt.*;
public class NO1HW2 extends JFrame
{
public void ShowBorderLayout()
{
Container mycontainer = getContentPane();
mycontainer.setLayout(new BorderLayout(10,10));
JPanel p1 = new JPanel();
for(int i = 1; i <= 3; i++)
p1.add(new JButton("Button " + i));
JPanel p2 = new JPanel();
for(int i = 4; i <= 6; i++)
p2.add(new JButton("Button " + i));
mycontainer.add(p1, BorderLayout.CENTER);
mycontainer.add(p2, BorderLayout.SOUTH);
}
public static void main(String args[])
{
NO1HW2 frame = new NO1HW2();
frame.setTitle("Show BorderLayout");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setVisible(true);
}
}
When I run the program the frame will pop up but that's it. The panels or buttons won't show. I asked my professor what the problem was and after making sure I set the frame visible to true he didn't know what else was wrong. Do y'all see anything that can cause it to not show the buttons?