GUI编程
学习GUI编程的好处
-
自己可以写心中想要的小工具
-
2. AWT
2.1 Awt介绍
-
包含了很多类和接口!
-
元素:窗口,按钮,文本框
3. Swing
public static void main(String[] args) {
//Java图像界面窗口
Frame frame = new Frame();
//设置窗口可见性
frame.setVisible(true);
//new Color()可以传递三种颜色参数
frame.setBackground(new Color(0xCE80B7));
//设置是窗口大小
frame.setSize(512,512);
//设置窗口弹出的初始位置
frame.setLocation(200,200);
//setResizable是否固定窗口大小true可以活动窗口,false固定窗口
frame.setResizable(false);
}
运行结果
public class MyFrame {
public static void main(String[] args) {
myFream myFream = new myFream(100, 100, 200, 200, Color.blue);
myFream myFream2 = new myFream(300, 100, 200, 200, Color.blue);
myFream myFream3 = new myFream(100, 300, 200, 200, Color.blue);
myFream myFream4 = new myFream(300, 300, 200, 200, Color.blue);
}
}
class myFream extends Frame{
static int id;
public myFream(int x, int y, int w, int h, Color color){
super("Myframe+"+(++id));//调用父类
setBounds(x,y,w,h);
setBackground(color);
setVisible(true);//设置窗口可见性
}
}