• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java小程序Dance with the stars(一):开始界面

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

用swing做了一个游戏初始界面。效果如下:

代码为:

 1 import javax.swing.*;
 2 import java.awt.*;
 3 import java.util.*;
 4 
 5 public class StartWindow {
 6 
 7     public static void main(String[] args) {
 8 
 9         // create the frame
10         JFrame frame = new JFrame();
11 
12         // create the host panel
13         JPanel panelHost = new JPanel();
14         BoxLayout layoutHost = new BoxLayout(panelHost, BoxLayout.Y_AXIS);
15         panelHost.setLayout(layoutHost);
16 
17         // labelTop is added into the host panel
18         JLabel labelTop = new JLabel("Dancing with the stars");
19         panelHost.add(labelTop);
20 
21         // panelSlider is for the two JSlider components
22         JPanel panelSlider = new JPanel();
23 
24         BoxLayout layoutSlider = new BoxLayout(panelSlider, BoxLayout.Y_AXIS);
25         panelSlider.setLayout(layoutSlider);
26 
27         // JSlider slider1
28         JLabel labelDifficulty = new JLabel("Select the difficulty level: ");
29         panelSlider.add(labelDifficulty);
30         JSlider slider1 = new JSlider(1, 10, 4);
31         slider1.setMajorTickSpacing(1);
32         slider1.setPaintTicks(true);
33         slider1.setSnapToTicks(true);
34         slider1.setPaintTrack(true);
35         slider1.setPaintLabels(true);
36 
37         panelSlider.add(slider1);
38 
39         // JSlider slider2
40         JLabel labelBalance = new JLabel("Assign your skill points to looks and dancing skills");
41         panelSlider.add(labelBalance);
42         JSlider slider2 = new JSlider(1, 10, 5);
43 
44         Hashtable<Integer, JLabel> labelsSlider2 = new Hashtable<>();
45         labelsSlider2.put(1, new JLabel("LOOKS"));
46         labelsSlider2.put(10, new JLabel("DANCING SKILLS"));
47 
48         slider2.setLabelTable(labelsSlider2);
49         slider2.setPaintLabels(true);
50         panelSlider.add(slider2);
51 
52         panelHost.add(panelSlider);
53 
54         // panelButton is for the two JButton components
55         JPanel panelButton = new JPanel();
56         JButton button1 = new JButton("High Scores");
57         JButton button2 = new JButton("START");
58         JButton button3 = new JButton("Exit");
59         panelButton.add(button1);
60         panelButton.add(button2);
61         panelButton.add(button3);
62         FlowLayout layoutButton = new FlowLayout();
63         panelButton.setLayout(layoutButton);
64         panelHost.add(panelButton);
65 
66         // labelBottom is added into the host panel
67         JLabel labelBottom = new JLabel("Dance your way to the TOP!");
68         panelHost.add(labelBottom);
69 
70         // panelHost and frame settings
71         frame.setTitle("Dance With Stars 0685182");
72         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
73         frame.setContentPane(panelHost);
74         frame.pack();
75         frame.setVisible(true);
76         frame.setResizable(false);
77         frame.setLocationRelativeTo(null);
78 
79     }
80 
81 }

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
小程序排错(redis导致)发布时间:2022-07-18
下一篇:
WePY框架开发的小程序中使用echarts折线图发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap