Java小程序Dance with the stars(一):开始界面
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Java小程序Dance with the stars(一):开始界面,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2997字,纯文字阅读大概需要5分钟。
内容图文
![Java小程序Dance with the stars(一):开始界面](/upload/InfoBanner/zyjiaocheng/848/ef4727313aab471484f2db22daf567dc.jpg)
用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 }
内容总结
以上是互联网集市为您收集整理的Java小程序Dance with the stars(一):开始界面全部内容,希望文章能够帮你解决Java小程序Dance with the stars(一):开始界面所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。