java 图形化界面 布局管理器
2024-10-19 14:52:17
package Layout;
import java.awt.*;
import javax.swing.*;
public class MyBorderLayout extends JFrame{
private JButton b1 = new JButton("东");
private JButton b2 = new JButton("南");
private JButton b3 = new JButton("西");
private JButton b4 = new JButton("北");
private JButton b5 = new JButton("中");
public MyBorderLayout(){ setTitle("用户界面");
setSize(500, 500);
setLocation(100, 100);
add(b1,BorderLayout.EAST);
add(b2,BorderLayout.SOUTH);
add(b3,BorderLayout.WEST);
add(b4,BorderLayout.NORTH);
add(b5,BorderLayout.CENTER); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
} public static void main(String[] args) {
MyBorderLayout l = new MyBorderLayout(); } }
package Layout;
import java.awt.*;
import java.util.HashMap;
import java.util.Map; import javax.swing.*;
public class MyFlowLayout extends JFrame{
private Map<String,JButton> map = new HashMap();
private JButton b = new JButton();
public MyFlowLayout(){
map.put("B1",new JButton("B1"));
map.put("B2",new JButton("B2"));
map.put("B3",new JButton("B3"));
map.put("B4",new JButton("B4"));
map.put("B5",new JButton("B5"));
this.setLayout(new FlowLayout());
// this.setLayout(new FlowLayout(FlowLayout.LEFT));
// this.setLayout(new FlowLayout(FlowLayout.RIGHT));
this.add(map.get("B1"));
this.add(map.get("B2"));
this.add(map.get("B3"));
this.add(map.get("B4"));
this.add(map.get("B5"));
this.setTitle("用户界面");
this.setSize(500, 400);
this.setLocation(400, 500);
this.setVisible(true);
} public static void main(String[] args) { MyFlowLayout l = new MyFlowLayout();
} }
package Layout;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;
import javax.swing.*;
public class MyGridLayout extends JFrame {
private Map<String,JButton> map = new HashMap();
public MyGridLayout (){ map.put("B1",new JButton("B1"));
map.put("B2",new JButton("B2"));
map.put("B3",new JButton("B3"));
map.put("B4",new JButton("B4"));
map.put("B5",new JButton("B5"));
map.put("B6",new JButton("B6"));
map.put("B7",new JButton("B7"));
map.put("B8",new JButton("B8"));
map.put("B9",new JButton("B9"));
this.add(map.get("B1"));
this.add(map.get("B2"));
this.add(map.get("B3"));
this.add(map.get("B4"));
this.add(map.get("B5"));
this.add(map.get("B6"));
this.add(map.get("B7"));
this.add(map.get("B8"));
this.add(map.get("B9")); this.setTitle("用户界面");
this.setSize(500, 600);
this.setLocation(500, 500);
this.setVisible(true);
this.setLayout(new GridLayout(3,3,15,15)); }
public static void main(String[] args) {
MyGridLayout l = new MyGridLayout(); } }
最新文章
- windows 常用命令整合--脚本工具
- 搭建Python+Django开发环境
- [问题2015S02] 复旦高等代数 II(14级)每周一题(第三教学周)
- Microsoft 2013 新技术学习笔记 二
- UI基础:UIActionSheet和UIAlterView
- UML类图新手入门级介绍
- VS2013中设置大小写的快捷键
- ☀【jQuery 优化】jQuery基础教程(第3版)
- 阻止IOS自动识别页面上的电话号码、email地址
- Qt之HTTPS登录(集成QNetworkAccessManager提前修改QSslConfiguration,然后post)
- Cngigure和BUS实现远端配置
- DHCP协议分析(Wireshark)
- [Java Web学习]JDBC事务处理
- NFC中国-中国第一NFC论坛,NFC中文论坛+NFC技术社区+NFC_电子发烧友网【申明:来源于网络】
- Bootstrap 插件收集
- Linux - 系统资源
- CSS3 Flex布局整理(一)
- Windows10(UWP)下的MEF
- Redis-3.2.0集群配置(redis cluster)
- VUE 实现tab切换页面效果