面板

主要步骤:

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. 稳住,传输层里的TCP与UDP协议

    传输层协议 1.TCP协议介绍及报文格式 2.TCP三次握手三次挥手 3.UDP协议介绍 1.传输层有两个协议:TCP(传输控制协议)  UDP(用户数据协议) . TCP是面向连接的,可靠的进程到进 ...

  2. 晋升挂了!leader说不是我技术不行

    大家好,我是对白. 今天给大家分享一位朋友在互联网大厂晋升失败的故事,不是每一位校招生第一年都可以稳稳晋升的,这不仅取决于你的业务收益,还取决于你是否会包装自己的项目,以下为原文. 晋升 去年秋季,我 ...

  3. Solution -「ARC 126E」Infinite Operations

    \(\mathcal{Description}\)   Link.   给定序列 \(\{a_n\}\),定义一次操作为: 选择 \(a_i<a_j\),以及一个 \(x\in\mathbb R ...

  4. c++ 字符串替换程序 p324

    字符串替换程序 C++ Primer 324页 // replace:从str字符串中查找oldVal字符串,如果找到就替换成newVal字符串. void replace(string &s ...

  5. 开源GenICam项目上手-1

    GenICam 说明 一个统一的编程规则,这样我们只需要一个应用软件,就可以支持符合标准的不同型号相机,当我们升级相机.更换相机时,不需要编写不同的软件代码. The goal of GenICamT ...

  6. 使用java程序完成大量文件目录拷贝工作

    java程序完成目录拷贝工作 背景描述:我目录有140多个,每个目录里面都有一个src目录.我现在想要所有的src目录移动到同一个目录中. package com.util.cp; import ja ...

  7. mysq数据库相信介绍大纲!!!!!!

    什么是数据库? 数据库(Database)是按照数据结构来安排.存储和办理数据的仓库. 每个数据库都有一个或多个不同的 API 用于创立,访问,办理,搜索和仿制所保存的数据. 我们也能够将数据存储在文 ...

  8. Swagger2简单实用

    前后端分离很好用的api <!--swagger--> <dependency> <groupId>io.springfox</groupId> < ...

  9. can_has_stdio?

    得到一个用±<>这样符号组成的五角星,结合题目stdio,估计是c语言编译后的文件 查到BrianFuck语言,找个在线编译器或者找到编译码(c++)得到flag 在线编译网站 brain ...

  10. [旧][Android] Retrofit 源码分析之 Retrofit 对象

    备注 原发表于2016.04.27,资料已过时,仅作备份,谨慎参考 前言 在上一周学习了一下 Retrofit 的执行流程.接下来的文章要更为深入地学习 Retrofit 的各个类,这次我们先学习一下 ...