面板Panel
面板
主要步骤:
1、new一个frame窗口
格式
Frame frame = new Frame()
2、设置窗口的大小、位置、可见性
3、设置frame窗口的布局格式(分为流式布局,东西南北中,表格布局等)
frame的布局能决定所添加的面板的位置
窗口布局的格式:
流式布局
frame.setLayout(new FlowLayout(FlowLayout.CENTRE))(居中)
frame.setLayout(new FlowLayout(FlowLayout.RIFT))(居左)
frame.setLayout(new FlowLayout(FlowLayout.RIGHT))(居右)
东西南北中布局
frame.setLayout(new BorderLayout.EAST)(东)
frame.setLayout(new BorderLayout.WEST)(西)
frame.setLayout(new BorderLayout.SOUTH)(南)
frame.setLayout(new BorderLayout.NORTH)(北)
frame.setLayout(new BorderLayout.CENTRE)(中)
表格布局
frame.setLayout(new GridLayout(r,c))(r行c列)
各个布局有关代码:
点击查看代码
package com.myblog.firstjavaproject2;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class GUI04 {
public static void main(String[] args) {
Frame frame=new Frame();
//流式布局
Button button1 = new Button("button1");
Button button2 = new Button("button2");
Button button3 = new Button("button3");
//设置为流式布局,且默认式居中的
//frame.setLayout(new FlowLayout());
//放在左边,在FlowLayout()的括号中添加FlowLayout.left即可
frame.setLayout(new FlowLayout(FlowLayout.LEFT));
frame.setSize(200,200);
//把按钮添加上去
frame.add(button1);
frame.add(button2);
frame.add(button3);
frame.setVisible(true);
//设置监听事件,用来关闭窗口
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});*/
//东西南北中
//设置按钮
Button button1 = new Button("east");
Button button2 = new Button("west");
Button button3 = new Button("north");
Button button4 = new Button("south");
Button button5 = new Button("centre");
//添加按钮,并且设置位置
frame.add(button1,BorderLayout.EAST);
frame.add(button2,BorderLayout.WEST);
frame.add(button3,BorderLayout.NORTH);
frame.add(button4,BorderLayout.SOUTH);
frame.add(button5,BorderLayout.CENTER);
frame.setBounds(400,400,400,400);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});*/
//表格布局
Button button1 = new Button("btn1");
Button button2 = new Button("btn2");
Button button3 = new Button("btn3");
Button button4 = new Button("btn4");
Button button5 = new Button("btn5");
frame.setLayout(new GridLayout(2,3));
frame.add(button1);
frame.add(button2);
frame.add(button3);
frame.add(button4);
frame.add(button5);
frame.setBounds(400,400,400,400);
frame.pack();
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
4、new一个面板Panel
格式
Panel panel = new Panel()
5、设置面板的布局
面板的布局可以决定添加在该面板上的组件的位置
同窗口布局,只将frame换成panel
6、设置面板的位置大小
7、将面板添加到窗口中
8、设置监听事件以关闭窗口
9,有关代码
点击查看代码
package com.myblog.firstjavaproject2;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class GUI03 {
public static void main(String[] args) {
// 需要窗口,则new一个Frame
Frame frame=new Frame("带面板的窗口");
//需要面板,则new一个Panel
Panel panel =new Panel();
//设置布局,默认面板中为空
frame.setLayout(null);
//设置窗口坐标和宽高
frame.setBounds(400,400,400,400);
//设置窗口背景颜色
frame.setBackground(new Color(1, 152, 253, 255));
//设置面板的坐标和宽高,注意这里面板的范围不能超出窗口的范围
panel.setBackground(new Color(1,1,1));
//设置面板的背景颜色
panel.setBounds(200,200,200,200);
//面板和窗口的关系,在窗口中添加一个面板
frame.add(panel);
//设置面板和窗口的可见性
frame.setVisible(true);
panel.setVisible(true);
//设置监听事件,即为关闭窗口,这里使用适配器 WindowAdapter(),然后添加 System.exit(0)
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
System.exit(0);
}
});
}
}
面板Panel的更多相关文章
- 044——VUE中组件之使用内容分发slot构建bootstrap面板panel
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- amazeui学习笔记--css(常用组件12)--面板Panel
amazeui学习笔记--css(常用组件12)--面板Panel 一.总结 1.面板基本样式:默认的 .am-panel 提供基本的阴影和边距,默认边框添加 .am-panel-default,内容 ...
- Java面板Panel的使用,监听窗口关闭事件
面板Panel的使用 待解决问题: 1.设计模式:适配器模式 2.frame.setLayout(null); package GUI; import javax.swing.*; import ja ...
- 轻量级jquery框架之--面板(panel)
面板需求: (1)支持可拖拽,面板将作为后期的布局组件.window组件.alert组件的基础. (2)支持自定义工具栏,工具栏位置定义在面板底部,工具栏依赖toolbar组件. (3)支持加载JSO ...
- 初识Sencha Touch:面板Panel
HTML代码: <!doctype html> <html> <head> <meta charset="utf-8"> <t ...
- Pandas面板(Panel)
面板(Panel)是3D容器的数据.面板数据一词来源于计量经济学,部分源于名称:Pandas - pan(el)-da(ta)-s. 3轴(axis)这个名称旨在给出描述涉及面板数据的操作的一些语义. ...
- 36.面板Ext.Panel使用
转自:https://www.cnblogs.com/linjiqin/archive/2011/06/22/2086620.html 面板Ext.Panel使用 概要 1.Ext.Panel概述 2 ...
- Pandas | 04 Panel 面板
面板(Panel)是3D容器的数据.面板数据一词来源于计量经济学,部分源于名称:Pandas - pan(el)-da(ta)-s. 3轴(axis)这个名称旨在给出描述涉及面板数据的操作的一些语义. ...
- JS Resizable Panel 练习
Resizable Panel HTML <!doctype html> <html> <head> <title>Resizable Panel< ...
随机推荐
- 数据库监测sql执行
SQL Server Profiler可以检测在数据上执行的语句,特别是有的项目不直接使用sql语句,直接使用ORM框架的系统处理数据库的项目,在调试sql语句时,给了很大的帮助. 之前写了使用SQL ...
- 稳过!华为微认证ModelArts实现智能花卉识别稳过!
华为微认证ModelArts实现智能花卉识别稳过! 目录 华为微认证ModelArts实现智能花卉识别稳过! ModelArts实现智能花卉识别的概述 ModelArts实现智能花卉识别的解决方案 M ...
- 国外很便宜的服务器 一年 2核2G 一年20美元
今年 服务器 //=====================================一下是去年的================================= 优惠码:zhujicepin ...
- 二叉树的基本操作(C语言版)
今天走进数据结构之二叉树 二叉树的基本操作(C 语言版) 1 二叉树的定义 二叉树的图长这样: 二叉树是每个结点最多有两个子树的树结构,常被用于实现二叉查找树和二叉堆.二叉树是链式存储结构,用的是二叉 ...
- MindSpore多元自动微分
技术背景 当前主流的深度学习框架,除了能够便捷高效的搭建机器学习的模型之外,其自动并行和自动微分等功能还为其他领域的科学计算带来了模式的变革.本文我们将探索如何用MindSpore去实现一个多维的自动 ...
- 北京太速科技-第六代Intel i7四核八线程6U VPX主控板
一.产品概述 该产品是一款基于第六代Intel i7四核八线程的高性能6U VPX刀片式计算机.产品提供了可支持全网状交换的高速数据通道,其中P1,P2各支持4个PCIe x4 Gen3总线接口,P3 ...
- Solution -「JOISC 2021」古老的机器
\(\mathcal{Description}\) Link. 这是一道通信题. 对于长度为一个 \(n\),仅包含字符 X, Y, Z 的字符串 \(s\),将其中 \(n\) 个字符按 ...
- linux系统中实用shell脚本,请收藏!
1.Dos攻击防范(自动屏蔽攻击 IP) #!/bin/bashDATE=$(date +%d/%b/%Y:%H:%M)LOG_FILE=/usr/local/nginx/logs/demo2.acc ...
- BI系统要自研还是采购?这篇文章告诉你
首先说一下目前市面上的BI工具都有哪些吧.总体上,其实分为免费和付费两大阵营.免费阵营里,为首的当然是GA(也就是谷歌分析).PowerBI,但是由于有墙的限制,很多公司没法使用前者.付费阵营里,近两 ...
- 业务人员可以进行自助ETL操作?这款BI工具你值得拥有
ETL是什么? ETL,是英文 Extract-Transform-Load 的缩写,用来描述将数据从来源端经过抽取(extract).转换(transform).加载(load)至目的端的过程.E ...