面板

主要步骤:

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的更多相关文章

  1. 044——VUE中组件之使用内容分发slot构建bootstrap面板panel

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. amazeui学习笔记--css(常用组件12)--面板Panel

    amazeui学习笔记--css(常用组件12)--面板Panel 一.总结 1.面板基本样式:默认的 .am-panel 提供基本的阴影和边距,默认边框添加 .am-panel-default,内容 ...

  3. Java面板Panel的使用,监听窗口关闭事件

    面板Panel的使用 待解决问题: 1.设计模式:适配器模式 2.frame.setLayout(null); package GUI; import javax.swing.*; import ja ...

  4. 轻量级jquery框架之--面板(panel)

    面板需求: (1)支持可拖拽,面板将作为后期的布局组件.window组件.alert组件的基础. (2)支持自定义工具栏,工具栏位置定义在面板底部,工具栏依赖toolbar组件. (3)支持加载JSO ...

  5. 初识Sencha Touch:面板Panel

    HTML代码: <!doctype html> <html> <head> <meta charset="utf-8"> <t ...

  6. Pandas面板(Panel)

    面板(Panel)是3D容器的数据.面板数据一词来源于计量经济学,部分源于名称:Pandas - pan(el)-da(ta)-s. 3轴(axis)这个名称旨在给出描述涉及面板数据的操作的一些语义. ...

  7. 36.面板Ext.Panel使用

    转自:https://www.cnblogs.com/linjiqin/archive/2011/06/22/2086620.html 面板Ext.Panel使用 概要 1.Ext.Panel概述 2 ...

  8. Pandas | 04 Panel 面板

    面板(Panel)是3D容器的数据.面板数据一词来源于计量经济学,部分源于名称:Pandas - pan(el)-da(ta)-s. 3轴(axis)这个名称旨在给出描述涉及面板数据的操作的一些语义. ...

  9. JS Resizable Panel 练习

    Resizable Panel HTML <!doctype html> <html> <head> <title>Resizable Panel< ...

随机推荐

  1. iOS中处理时间的类

      登录|注册     sakulafly的专栏       目录视图 摘要视图 订阅 Markdown博文大赛清新开启    天天爱答题 一大波C币袭来    中国云计算大会演讲议题公布     大 ...

  2. CSS快速入门(四)

    目录 CSS快速入门(四) 浮动 float属性 clear属性 浮动解决的问题及其影响 解决父标签塌陷的方法 浮动案例 定位 什么是脱离文档流 定位的两种方法 position定位 static定位 ...

  3. AI模型运维——NVIDIA驱动、cuda、cudnn、nccl安装

    目前大部分使用GPU的AI模型,都使用的英伟达这套. 需要注意的是,驱动.cuda.cudnn版本需要一一对应,高低版本互不兼容. 驱动和cuda对应关系:https://docs.nvidia.co ...

  4. Solution -「Gym 102979L」 Lights On The Road

    \(\mathcal{Description}\)   Link.   给定序列 \(\{w_n\}\),选择 \(i\) 位置的代价为 \(w_i\),要求每个位置要不被选择,要不左右两个位置至少被 ...

  5. c++ 程序编译后运行时的内存分配

    程序编译后运行时的内存分配 太好的文章了,看到不得不转,转自:http://blog.sina.com.cn/s/blog_5420e0000101a0w1.html 一.编译时与运行时的内存情况 1 ...

  6. 【程序员的实用工具推荐】 Mac 效率神器 Alfred

    Alfred 是一款功能非常强大,能有效提升 Mac 电脑使用效率的神器.可以说有了 Alfred 你就基本上可以脱离鼠标实现各种操作.相比 Mac 自带的聚焦搜索,完全可以称得上拥有碾压性的优势. ...

  7. k8s中运行busybox

    简介 参考百度百科 BusyBox 是一个集成了三百多个最常用Linux命令和工具的软件. BusyBox 包含了一些简单的工具,例如ls.cat和echo等等,还包含了一些更大.更复杂的工具,例gr ...

  8. 自助式BI工具怎么选?这款用过都说好!

    随着大数据时代的到来,很多公司的业务数据量不断增长,公司必须集中精力管理数据,并在BI工具的帮助下进行数据分析,以便从过去的数据中获得洞察力,预测未来的发展.近年来,随着企业对数据的关注度的增加,企业 ...

  9. BI报表系统该如何集成到其他系统呢?

    近期小麦我经常收到很多用户的反馈,想知道Smartbi的报表能不能从微信/钉钉之类的直接跳转到已做好的报表页面?他们都希望通过这种方式尽可能地避免由于各个管理软件账号密码不同而造成的不便,能够在日常工 ...

  10. 【C# .Net GC】垃圾回收算法 应用程序线程运行时,

    触发垃圾回收算法的条件 触发垃圾回收的条件 当满足以下条件之一时将发生垃圾回收: 操作系统报告低内存请看(将触发第2代垃圾回收). 这是通过 OS 的内存不足通知或主机指示的内存不足检测出来. 由托管 ...