[英]how can I set Gui like this photo
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();
}
}
I want to set likes this photo.我想设置喜欢这张照片。
When click start button go to the game state当点击开始按钮 go 到游戏 state
But when I write the code.但是当我写代码时。
Can you advise me how to write the code likes my first photo?你能告诉我如何编写代码,就像我的第一张照片一样吗?
This is just a rough design.这只是一个粗略的设计。 You want to nest different layout methods.
您想嵌套不同的布局方法。 This should be an accurate framework for your design, you can tweak some numbers (like spaces etc.) to your own liking.
这应该是您设计的准确框架,您可以根据自己的喜好调整一些数字(如空格等)。
//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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.