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

public class LayoutTest {
    public static void main(String[] args) {
	LayoutTestFrame test = new LayoutTestFrame(); 
	test.setLayout(new BorderLayout(5,5)); 
	
	// add components
	JButton ok = new JButton("ok"); 
	ok.setBackground(Color.green); 
	JButton cancel = new JButton("cancel"); 
	cancel.setBackground(Color.red);

	JLabel question = new JLabel("Save file?"); 
	question.setOpaque(true);
	question.setBackground(Color.yellow);
	
	JTextField filename = new JTextField(10);

	// inner class
	class MyCanvas extends JPanel {
	    public void paintComponent(Graphics g){
		super.paintComponent(g);
		setBackground(Color.white);
		setOpaque(true);
		g.drawString("test",10,20); 
	    }
	}

	MyCanvas myCanvas = new MyCanvas();
	myCanvas.setSize(40,40);
	
	test.getContentPane().add(question, BorderLayout.NORTH);
	test.getContentPane().add(ok, BorderLayout.WEST); 
	test.getContentPane().add(cancel, BorderLayout.EAST); 
	test.getContentPane().add(filename, BorderLayout.SOUTH); 
	test.getContentPane().add(myCanvas, BorderLayout.CENTER); 

	test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	test.setVisible(true); 
    }
}

class LayoutTestFrame extends JFrame {
    public LayoutTestFrame() {
	setBackground(Color.lightGray);
	setSize(400,300);
	setLocation(100,100);
    }
}

