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

public class LayoutTest {
    public static void main(String[] args) {
	LayoutTestFrame test = new LayoutTestFrame(); 
	//test.setLayout(new FlowLayout()); 
	//test.setLayout(new FlowLayout(FlowLayout.LEFT)); 
	test.setLayout(new FlowLayout(FlowLayout.LEFT, 20, 20)); 
	
	// add components
	JButton ok = new JButton("ok"); 
	JButton cancel = new JButton("cancel"); 
	JLabel question = new JLabel("Save file?"); 
	JTextField filename = new JTextField(10);

	// inner class
	class MyCanvas extends JPanel {
	    public Dimension getPreferredSize() { return new Dimension(100,40); }

	    public void paintComponent(Graphics g){
		super.paintComponent(g);

		setBackground(Color.white);
		setOpaque(true);
		g.drawString("test",10,20); 
	    }
	}
	MyCanvas myCanvas = new MyCanvas();
	
	test.getContentPane().add(question);
	test.getContentPane().add(ok); 
	test.getContentPane().add(cancel); 
	test.getContentPane().add(filename); 
	test.getContentPane().add(myCanvas); 

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

class LayoutTestFrame extends JFrame {
    public LayoutTestFrame() {
	getContentPane().setBackground(Color.green);
	setSize(600,300);
	setLocation(100,100);
    }
}

