面板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< ...
随机推荐
- 部署YUM仓库及NFS共享服务
部署YUM仓库及NFS共享服务 目录 部署YUM仓库及NFS共享服务 一.YUM仓库服务 1. YUM概述 2. 部署YUM软件仓库 (1)准备安装源 ①YUM仓库的种类 ②RPM软件包的来源 ③构建 ...
- 分享刚出炉的基于Blazor技术的Web应用开发框架
这是最近刚刚重构完成的项目,有点迫不及待的分享给大家,为了跟上技术升级把原来基于MVC Razor Page开源项目 RazorPageCleanArchitecture 进行重构, 前端用Blazo ...
- Node介绍
https://segmentfault.com/a/1190000006121183 一. 概述 Node.js是基于Chrome JavaScript运行时建立的一个平台,实际上它是对Google ...
- 36、python并发编程之多线程(操作篇)
目录: 一 threading模块介绍 二 开启线程的两种方式 三 在一个进程下开启多个线程与在一个进程下开启多个子进程的区别 四 练习 五 线程相关的其他方法 六 守护线程 七 Python GIL ...
- Solution -「HDU 1788」CRT again
\(\mathcal{Description}\) Link. 解同余方程组: \[x\equiv m_i-a\pmod{m_i} \] 其中 \(i=1,2,\dots,n\). \ ...
- NTFS ADS(备用数据流)
NTFS Alternate Data Stream(ADS) 1993年微软推出了基于流行的NT平台的Windows NT操作系统.之后,NTFS作为WIndows开发基于NT的操作系统时的首选 ...
- c++ istream_iterator ostream_iterator
istream_iterator/ostream_iterator void stream_iter_odd_even(const string &in_file, const string ...
- Vue 源码解读(3)—— 响应式原理
前言 上一篇文章 Vue 源码解读(2)-- Vue 初始化过程 详细讲解了 Vue 的初始化过程,明白了 new Vue(options) 都做了什么,其中关于 数据响应式 的实现用一句话简单的带过 ...
- showdoc升级问题,showdoc错误日志
showdoc自带错误日志.目录位于网站根目录的server/Application/Runtime/Logs/Api目录下,如果没有任何内容需要添加可写权限. showdoc升级后,建议把MySQL ...
- python爬虫:爬虫的简单介绍及requests模块的简单使用
python爬虫:爬虫的简单介绍及requests模块的简单使用 一点点的建议: (学习爬虫前建议先去了解一下前端的知识,不要求很熟悉,差不多入门即可学习爬虫,如果有不了解的,我也会补充个一些小知识. ...