为了账号安全,请及时绑定邮箱和手机立即绑定

我怎样才能像这张照片一样设置 Gui

我怎样才能像这张照片一样设置 Gui

手掌心 2023-08-16 10:19:03
package matchgame;import java.awt.BorderLayout;import javax.swing.*;import javax.swing.border.Border;public class Start_Manu extends JFrame {    Start_Manu()    {        JLabel welcome=new JLabel("Welcome to Match Card Game ☺");        JButton start=new JButton("Start");        JPanel manustart=new JPanel(new BorderLayout());        manustart.add(welcome,BorderLayout.NORTH);        manustart.add(start,BorderLayout.CENTER);        add(manustart);        //set Frame        setSize(800, 600);        setTitle("Match Card Game");        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        setLocationRelativeTo(null);        setVisible(true);    }    public static void main(String[] args) {        Start_Manu a=new Start_Manu();    }}我想设置喜欢这张照片。点击开始按钮后进入游戏状态但是当我写代码的时候。你能告诉我如何编写像我的第一张照片一样的代码吗?
查看完整描述

1 回答

?
三国纷争

TA贡献1804条经验 获得超7个赞

这只是一个粗略的设计。您想要嵌套不同的布局方法。这应该是您设计的准确框架,您可以根据自己的喜好调整一些数字(如空格等)。


        //Main Panel to contain everything

        JPanel main = new JPanel();

        main.setLayout(new BoxLayout(main,BoxLayout.Y_AXIS));


        JLabel welcome=new JLabel("Welcome to Match Card Game ☺");

        //Setting prefered Font-Size

        welcome.setFont(new Font(welcome.getName(), Font.PLAIN, 24));



        JButton start=new JButton("Start Game");


        //Change button size and apparence

        start.setPreferredSize(new Dimension(150,50));

        start.setContentAreaFilled(false);



        //Add two sub-panels for advanced positioning

        JPanel welcome_p=new JPanel(new FlowLayout(1,0,150));

        JPanel button_p=new JPanel();


        //Set welcomepanel size to lower space to Button

        welcome_p.setPreferredSize(new Dimension(300,150));

        welcome_p.add(welcome);


        button_p.add(start);

        main.add(welcome_p);


        main.add(button_p);


        add(main);

        setSize(800, 600);

        setTitle("Match Card Game");

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setLocationRelativeTo(null);

        setVisible(true);


查看完整回答
反对 回复 2023-08-16
  • 1 回答
  • 0 关注
  • 61 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信