Have been studying java for the first half of the year and am now just getting started on GUI.
Having a little trouble understanding how to add a JPanel to a JFrame from an external class.
class one
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class DrawingFrame extends JFrame{
protected BottomPanel bottom;
public DrawingFrame() {
bottom = new BottomPanel();
JPanel p1 = new JPanel();
p1.setBackground(Color.BLACK);
add(p1, BorderLayout.NORTH);
add(bottom, BorderLayout.EAST);
}
public static void main(String[] args) {
DrawingFrame frame = new DrawingFrame();
frame.setTitle("Assesed Lab GUI");
frame.setSize(960, 700);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class 2
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JPanel;
public class BottomPanel extends JPanel{
public BottomPanel(){
JPanel bottom = new JPanel();
bottom.setBackground(Color.BLUE);
bottom.setVisible(true);
}
}
so as is the panel created in the first class and added displays in North however I am unable to add the JPanel bottom to East. It compiles and runs but remains blank everywhere except in the North panel.
Any help would be greatly appreciated.

New Topic/Question
Reply



MultiQuote



|