Java(42)_不使用布局管理器
阿新 • • 發佈:2018-11-29
image cti visible import button setbounds 工具 action 添加按鈕
package MYSQK.example01; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; /** * 不使用布局管理器 */ public class example01 { public static void main(String[] args){ Frame f = new Frame("不使用布局管理器"); f.setLayout(null);//取消frame的布局管理器 f.setSize(300,150); Button button1 =new Button("press"); Button button2 =new Button("pop"); //設置按鈕顯示位置和大小 button1.setBounds(40,60,100,30); button2.setBounds(140,90,100,30); // 添加按鈕到窗體 f.add(button1); f.add(button2); f.setVisible(true); } }
不使用布局管理器是不是更靈活一些呢?還有就是其實javaGUI確實用的少了。現在很多項目都是B/S架構的,通過瀏覽器,除非是寫個小工具啥的可能會用到。
Java(42)_不使用布局管理器