简单gui

 
 
import java.awt.Button;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Test {
	public static void main(String[] args) {
		new Test().demo();;
		
		

	}

	 void demo() {
		Frame f = new Frame("Demon's Frame");
		// 窗口大小
		f.setSize(400, 400);
		// 窗口位置(左右
		f.setLocation(500, 300);
		// 容器布局为null >>窗口.setLayout(null),才可改变按钮大小
		f.setLayout(null);
		Button b = new Button("登录");

		// setBounds(x,y,width,height);
		// x:组件在容器X轴上的起点 y:组件在容器Y轴上的起点
		// width:组件的长度 height:组件的
		
		b.setBounds(80, 180, 30, 30);
		// 添加按钮
		f.add(b);
		//关闭窗口
		 f.addWindowListener(new WindowAdapter() {
	          @Override
	          public void windowClosing(WindowEvent e)
	          {
	             System.exit(0);
	          }
	      });
		// 使得窗口可见
		f.setVisible(true);
		// 验证程序是否被执行了
		System.out.println("Successful!");
	}


}

  



 

猜你喜欢

转载自www.cnblogs.com/Demonfeatuing/p/9057496.html
GUI