我将如何为这样的Gui设置布局 [英] How Would I Set Up A Layout For A Gui Like This

查看:72
本文介绍了我将如何为这样的Gui设置布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何设置一个layoutmanager来创建这样的GUI?

https://docs.google.com/drawings/d/1te1IpBLzcFnV8KXq4-RMQnRMQviyuaW7vUN0s7jODlA/edit?usp=sharing [ ^ ]



i可以设置全部actionevents和使按钮做东西等但我不知道如何使用layoutmanager正确定位面板和按钮。

How would i set up a layoutmanager to create a GUI like this?
https://docs.google.com/drawings/d/1te1IpBLzcFnV8KXq4-RMQnRMQviyuaW7vUN0s7jODlA/edit?usp=sharing[^]

i can set up all the actionevents and make the buttons do stuff etc but i just dont know how to position the panels and buttons correctly using a layoutmanager.

推荐答案

您的gui分裂 [ ^ ]

您可以看到这3个红色面板下面有一个面板。



编辑:想一想关于编码。单独的GUI和Control,设置一个服务层。

你可能先写一个描述(大提示!)。



< b> EDIT2 :

请看这里:布局管理器的可视指南 [ ^ ]



你可以试试这个简单的 JFrame 。请创建一个游乐场项目并尝试一下:



Your gui split[^]
You can see that there is a panel beneath those 3 red panels.

EDIT: Think about the coding. Separate GUI and Control, set up a service layer.
You're probably writing a description first (big hint!).

EDIT2:
PLease take a look here: A Visual Guide to Layout Managers[^]

and you might try this simple JFrame. Please create yourself a playground project and try things out there:

import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;


public class MyFrame extends JFrame {

	private JPanel panelLeft = new JPanel();
	private JPanel panelRight = new JPanel();
	private JPanel panelLeftTop = new JPanel();
	private JPanel panelLeftBottom = new JPanel();
	
	public MyFrame(){
		this.ignition();
	}
	
	private void ignition() {
		this.setSize(800,600);
		this.setLayout(new GridLayout(1, 2));
		
		panelLeft.setBackground(Color.RED);
		panelRight.setBackground(Color.GREEN);
		panelLeftTop.setBackground(Color.YELLOW);
		panelLeftBottom.setBackground(Color.BLUE);
		
		// inside left panel
		panelLeftTop.setSize(400,300);
		panelLeftBottom.setSize(400,300);
		
		//giving left panel a layout and adding components
		panelLeft.setLayout(new GridLayout(2,1));
		panelLeft.add(panelLeftTop);
		panelLeft.add(panelLeftBottom);
		
		//adding the panels to the JFrame
		this.add(panelLeft);
		this.add(panelRight);
	}

	public static void main(String[] args) {
		new MyFrame().setVisible(true);
	}

}


这篇关于我将如何为这样的Gui设置布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆