栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

GUI fame窗口

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

GUI fame窗口

frame窗口
package GUI1;
​
​
import java.awt.*;
​
public class frame{
    public static void main(String[] args) {
        java.awt.frame F1=new java.awt.frame("我的图形界面");
        F1.setVisible(true);   //可视化
        F1.setSize(500,300);  //边框的大小
​
        F1.setBackground(Color.pink);   //颜色
        F1.setLocation(100,100);  //位置
        F1.setResizable(false);    //不能变大
​
​
    }
}
package GUI1;
​
import java.awt.*;
​
public class frame2 {
    public static void main(String[] args) {
        new Fam(200,144,200,345,Color.darkGray);
        new Fam(200,144,100,345,Color.green);
        new Fam(300,344,200,345,Color.pink);
        new Fam(300,544,200,345,Color.darkGray);
​
    }
}
class Fam extends frame {
    static int id=0;
    public Fam (int x,int y,int w,int h,Color color){
       super("fame+"+(++id));
       setVisible(true);   //可视化
       setBounds(x, y, w, h);
         setBackground(color);//颜色
​
    }
}

多个窗口;

package GUI1;
​
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
​
public class TestPane {
    public static void main(String[] args) {
        frame f1=new frame();
        Panel p1=new Panel();
        f1.setLayout(null);   //设置布局;
        f1.setBounds(300,300,500,500);
        f1.setBackground(new Color(0xB35269));
        p1.setBounds(50,50,400,400);
        p1.setBackground(new Color(193, 138, 42));
        f1.add(p1);
       f1.setVisible(true);
       f1.addWindowListener(new WindowAdapter() {
           @Override
           public void windowClosing(WindowEvent e) {
               super.windowClosing(e);
               System.exit(0);
           }
       });
    }
}

面板以及其关闭;


布局管理器:

package GUI1;
​
import java.awt.*;
​
public class TestFlowLayout {
    public static void main(String[] args) {
        frame frame=new frame();
        Button button=new Button("按钮");
        Button button2=new Button("按钮");
        Button button3=new Button("按钮");
        frame.setLayout(new FlowLayout(FlowLayout.LEFT));
        frame.setSize(200,200);
        frame.setVisible(true);
        frame.add(button);
        frame.add(button2);
        frame.add(button3);
    }
}

package GUI1;
​
import java.awt.*;
​
public class TestBoderLayout {
    public static void main(String[] args) {
        frame frame=new frame("testboderlayout");
        Button east = new Button("east");
        Button west = new Button("west");
        Button north = new Button("north");
        Button south = new Button("south");
        Button center = new Button("center");
        frame.add(east,BorderLayout.EAST);
        frame.add(west,BorderLayout.WEST);
        frame.add(north,BorderLayout.NORTH);
        frame.add(south,BorderLayout.SOUTH);
        frame.add(center,BorderLayout.CENTER);
        frame.setVisible(true);
        frame.setBounds(200,400,400,500);
    }
}

东西南北中的布局;

package GUI1;
​
import java.awt.*;
​
public class TestGridLayOUT {
    public static void main(String[] args) {
        frame frame=new frame("testboderlayout");
        Button bt1 = new Button("bt1");
        Button bt2 = new Button("bt2");
        Button bt3 = new Button("bt3");
        Button bt4 = new Button("bt4");
        Button bt5 = new Button("bt5");
        Button bt6 = new Button("bt6");
        frame.setLayout(new GridLayout(3,3));
        frame.add(bt1);
        frame.add(bt2);
        frame.add(bt3);
        frame.add(bt4);
        frame.add(bt5);
        frame.add(bt6);
        frame.pack();  //自动选择优秀的布局
        frame.setVisible(true);
    }
}

frame.pack(); //自动选择优秀的布局

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/284837.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号