java的frame.setBounds(500,250,1,1);的宽高设置无效是怎么回事?

不是simaguo 发布于 2016/09/03 14:47
阅读 548
收藏 0
package java10Awt;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;

public class Calculator {
	public static void main(String[] args) {
		Frame frame = new Frame("计算器");
		frame.setBounds(500,250,1,1);
		
		frame.setLayout(new BorderLayout());
		frame.add(new TextField(40), BorderLayout.NORTH);
		frame.add(gridPanel());
		
		
		frame.pack();
		frame.setVisible(true);
	}
	
	protected static Panel gridPanel(){
		Panel panel = new Panel(new GridLayout(3, 5,5,5));
		String[] key = {"0","1","2","3","4","5","6","7","8","9","+","-","*","/","="};
		for(int i=0; i<key.length;i++){
			panel.add(new Button(key[i]));
		}
		return panel;
	}
}

无论我frame.setBounds(500,250,1,1);最后两个参数设成多大,窗口都是一样的宽高。




加载中
返回顶部
顶部