第一次编写Java流布局图形界面
作者:qq_26525215 时间:2023-10-13 08:27:11
本文实例为大家分享了Java流布局图形界面编写代码,供大家参考,具体内容如下
package jisuanqi;
import java.awt.*;
public class MyFrame extends Frame{
//继承Frame类
public MyFrame() {
super("第一个图形界面");
//设置框架窗口标题
this.setSize(200, 130);
//设置组件尺寸(宽,高)
this.setLocation(300, 240);
//设置组件的显示位置
this.setBackground(Color.lightGray);
//设置组件的背景颜色
this.setLayout(new FlowLayout());
//设置的容器布局为流布局,居中
this.add(new Label("姓名:"));
//创建标签,添加到框架上
this.add(new TextField("陈浩翔",10));
//创建文本行,10列
this.add(new Label("密码"));
this.add(new TextField(10));
//创建10列的文本行
this.add(new Button("OK"));
//创建按钮
this.add(new Button("Cancel"));
//创建按钮
this.setVisible(true);
//是否显示框架窗口,必须在添加组件后
}
public static void main(String[] args) {
new MyFrame();
}
}
第一次写图形界面的源代码,小小的激动啊。
流布局的图形构造方法默认为居中排列;
对齐常量:
LEFT(0):左对齐
CENTER(1):居中
RIGHT(2):右对齐
public FlowLayout(int align)
//align参数指定对齐方式,取值为对齐常量。
来源:http://blog.csdn.net/qq_26525215/article/details/49721107
标签:java,流布局,图形界面
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
JavaAPI的使用方法详解
2022-10-30 23:00:40
![](https://img.aspxhome.com/file/2023/5/105945_0s.png)
Android仿Flipboard动画效果的实现代码
2022-07-29 13:52:02
![](https://img.aspxhome.com/file/2023/1/137471_0s.gif)
C#窗体布局方式详解
2023-09-26 11:17:32
基于C#制作一个休息提醒闹钟的详细步骤
2022-01-23 06:14:38
![](https://img.aspxhome.com/file/2023/9/81059_0s.png)
Android实现手势密码功能
2023-08-29 05:41:07
![](https://img.aspxhome.com/file/2023/8/106058_0s.gif)
c#多线程之线程基础
2022-10-06 20:34:44
基于OpenGL实现多段Bezier曲线拼接
2022-03-07 03:47:31
![](https://img.aspxhome.com/file/2023/7/112287_0s.jpg)
Android实现背景图滑动变大松开回弹效果
2022-10-15 10:45:15
![](https://img.aspxhome.com/file/2023/9/108239_0s.jpg)
C#通过反射打开相应窗体方法分享
2023-09-21 07:37:14
Java数据结构及算法实例:快速计算二进制数中1的个数(Fast Bit Counting)
2022-07-31 14:39:23
轻松掌握Java观察者模式
2023-10-10 22:34:54
gson对象序列化的示例
2023-11-25 08:54:28
![](https://img.aspxhome.com/file/2023/6/59956_0s.png)
Android NDK开发(C语言-文件读写)
2022-07-04 17:02:09
Mybatis实现关联关系映射的方法示例
2022-09-18 05:36:12
![](https://img.aspxhome.com/file/2023/9/128909_0s.jpg)
解决IDEA springboot"spring-boot-maven-plugin"报红问题
2023-08-15 21:29:19
![](https://img.aspxhome.com/file/2023/3/72543_0s.png)
使用SpringBoot配置多数据源的经验分享
2022-05-25 04:02:57
![](https://img.aspxhome.com/file/2023/1/97931_0s.png)
Java即将引入新对象类型来解决内存使用问题
2023-03-30 18:12:42
![](https://img.aspxhome.com/file/2023/5/70935_0s.png)
分享几个Java工作中实用的代码优化技巧
2023-11-28 12:04:50
![](https://img.aspxhome.com/file/2023/0/59890_0s.webp)
Java实现Android拼图游戏设计过程解析
2021-10-02 17:13:18
![](https://img.aspxhome.com/file/2023/2/94232_0s.png)
Java案例使用比较排序器comparator实现成绩排序
2023-10-16 01:37:24