请问下 要做这样两个界面用java的swing做 该怎么去布局开发。。有谁做过
2个回答
展开全部
具体字体大小之类的细节你可以根据自己需要改动下就行
package my.test.main;
import java.awt.BorderLayout;
public class First extends JDialog {
private final JPanel contentPanel = new JPanel();
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
First dialog = new First();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the dialog.
*/
public First() {
setBounds(100, 100, 450, 300);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBackground(new Color(90, 155, 213));
contentPanel.setLayout(new GridLayout(1, 1));
getContentPane().add(contentPanel, BorderLayout.CENTER);
JLabel lblNewLabel = new JLabel("Hi,I hope you are having a good day!");
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
contentPanel.add(lblNewLabel);
}
}
package my.test.main;
import java.awt.BorderLayout;
public class Second extends JDialog {
private final JPanel contentPanel = new JPanel();
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
Second dialog = new Second();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the dialog.
*/
public Second() {
setBounds(100, 100, 450, 276);
getContentPane().setLayout(new BorderLayout());
contentPanel.setLayout(new BorderLayout(0, 0));
getContentPane().add(contentPanel, BorderLayout.CENTER);
{
JPanel panel = new JPanel();
panel.setBackground(new Color(90, 155, 213));
FlowLayout flowLayout = (FlowLayout) panel.getLayout();
flowLayout.setAlignment(FlowLayout.LEFT);
contentPanel.add(panel, BorderLayout.NORTH);
{
JLabel lblNewLabel = new JLabel("Please select an option:");
panel.add(lblNewLabel);
}
}
{
JPanel panel = new JPanel();
panel.setBackground(new Color(90, 155, 213));
FlowLayout flowLayout = (FlowLayout) panel.getLayout();
flowLayout.setAlignment(FlowLayout.RIGHT);
contentPanel.add(panel, BorderLayout.SOUTH);
{
JLabel lblNewLabel_1 = new JLabel("Option selected:_________");
panel.add(lblNewLabel_1);
}
}
{
JPanel panel = new JPanel();
panel.setBorder(new EmptyBorder(0, 20, 0, 20));
panel.setBackground(new Color(90, 155, 213));
contentPanel.add(panel, BorderLayout.CENTER);
panel.setLayout(new GridLayout(2, 3, 20, 20));
{
JPanel panel_1 = new JPanel();
panel_1.setBackground(new Color(157, 195, 231));
panel.add(panel_1);
panel_1.setLayout(new GridLayout(2, 1, 0, 0));
{
JLabel lblNewLabel_2 = new JLabel("1");
lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
panel_1.add(lblNewLabel_2);
}
{
JLabel lblNewLabel_3 = new JLabel("fish");
lblNewLabel_3.setHorizontalAlignment(SwingConstants.CENTER);
panel_1.add(lblNewLabel_3);
}
}
{
JPanel panel_1 = new JPanel();
panel_1.setBackground(new Color(244, 177, 132));
panel.add(panel_1);
panel_1.setLayout(new GridLayout(2, 1, 0, 0));
{
JLabel lblNewLabel_2 = new JLabel("2");
lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
panel_1.add(lblNewLabel_2);
}
{
JLabel lblNewLabel_3 = new JLabel("meat");
lblNewLabel_3.setHorizontalAlignment(SwingConstants.CENTER);
panel_1.add(lblNewLabel_3);
}
}
{
JPanel panel_1 = new JPanel();
panel_1.setBackground(new Color(129, 225, 249));
panel.add(panel_1);
panel_1.setLayout(new GridLayout(2, 1, 0, 0));
{
JLabel lblNewLabel_2 = new JLabel("3");
lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
panel_1.add(lblNewLabel_2);
}
{
JLabel lblNewLabel_3 = new JLabel("rice");
lblNewLabel_3.setHorizontalAlignment(SwingConstants.CENTER);
panel_1.add(lblNewLabel_3);
}
}
{
JPanel panel_1 = new JPanel();
panel_1.setBackground(new Color(254, 254, 168));
panel.add(panel_1);
panel_1.setLayout(new GridLayout(2, 1, 0, 0));
{
JLabel lblNewLabel_2 = new JLabel("4");
lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
panel_1.add(lblNewLabel_2);
}
{
JLabel lblNewLabel_3 = new JLabel("noodle");
lblNewLabel_3.setHorizontalAlignment(SwingConstants.CENTER);
panel_1.add(lblNewLabel_3);
}
}
{
JPanel panel_1 = new JPanel();
panel_1.setBackground(new Color(230, 146, 224));
panel.add(panel_1);
panel_1.setLayout(new GridLayout(2, 1, 0, 0));
{
JLabel lblNewLabel_2 = new JLabel("5");
lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
panel_1.add(lblNewLabel_2);
}
{
JLabel lblNewLabel_3 = new JLabel("drink");
lblNewLabel_3.setHorizontalAlignment(SwingConstants.CENTER);
panel_1.add(lblNewLabel_3);
}
}
{
JPanel panel_1 = new JPanel();
panel_1.setBackground(new Color(143, 251, 166));
panel.add(panel_1);
}
}
}
}
更多追问追答
追问
你这个是自己 生成的吗?
追答
对啊 ,自己写的啊
2016-06-06
展开全部
使用JPanel 套别的组件 。。。。。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询