1.看lz的需求应该适合GridBagLayout.把Button的大小固定,让TextField自适应宽度.
2.fr.setResizable(false);既然不可变,也可以用XYLayout.

解决方案 »

  1.   

    package com.ufinty.Spring.usespringMVC;import java.awt.*; 
    import java.awt.event.*; public class dddd 

    public static void main(String args[]){ 
    Frame fr = new Frame("日历记事本"); 
    fr.setSize(650,400); 
    fr.setLocation(350,200); 
    fr.setBackground(Color.GRAY); 
    fr.setResizable(false);//设置窗口大小不可变!!! 
    fr.addWindowListener(new WindowAdapter(){ 
    public void windowClosing(WindowEvent e){ 
    System.exit(0);} 
    }); 
    fr.setLayout(null); 
    Panel p1 = new Panel(); 
    Panel p2 = new Panel(); 
    Panel p3 = new Panel(); 
    p3.setBounds(0,20,400,40); //在此做了修改,原来你写的距顶端为0,不过打开的窗口有一段距离
    p1.setBounds(0, 60, 400, 340); 
    p2.setBounds(400, 0, 250, 400); 
    p3.setBackground(Color.BLUE); 
    p2.setBackground(Color.cyan); 
    p3.setLayout(new FlowLayout()); 
    Button b1= new Button("去年");
    b1.setBounds(10, 10, 50, 50);
    p3.add(b1); 
    p3.add(new TextField(4)); 
    p3.add(new Button("明年")); 
    p3.add(new Button("上月")); 
    p3.add(new TextField(2)); 
    p3.add(new Button("下月")); 
    fr.add(p3); 
    fr.add(p1); 
    fr.add(p2); 
    fr.setVisible(true);