Advertisement
zontak

TitleMenuTesting

May 15th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. package com.tutorialspoint.gui;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.io.IOException;
  6.  
  7. import javax.imageio.ImageIO;
  8. import javax.swing.*;
  9.  
  10. public class SwingControlDemo {
  11.  
  12. private JFrame mainFrame;
  13. private JLabel headerLabel;
  14. private JLabel statusLabel;
  15. private JPanel controlPanel;
  16.  
  17. public SwingControlDemo(){
  18. prepareGUI();
  19. }
  20.  
  21. public static void main(String[] args){
  22. SwingControlDemo swingControlDemo = new SwingControlDemo();
  23. swingControlDemo.showButtonDemo();
  24. }
  25.  
  26. private void prepareGUI(){
  27. mainFrame = new JFrame("Pong");
  28. mainFrame.setSize(1280,720);
  29. mainFrame.setLayout(new GridLayout(5, 2));
  30. mainFrame.addWindowListener(new WindowAdapter() {
  31. public void windowClosing(WindowEvent windowEvent){
  32. System.exit(0);
  33. }
  34. });
  35. headerLabel = new JLabel("", JLabel.CENTER);
  36. statusLabel = new JLabel("",JLabel.CENTER);
  37.  
  38. statusLabel.setSize(350,100);
  39.  
  40. controlPanel = new JPanel();
  41. controlPanel.setLayout(new FlowLayout());
  42.  
  43. mainFrame.add(headerLabel);
  44. mainFrame.add(controlPanel);
  45. mainFrame.add(statusLabel);
  46. mainFrame.setVisible(true);
  47. }
  48.  
  49. private static ImageIcon createImageIcon(String path,
  50. String description) {
  51. java.net.URL imgURL = SwingControlDemo.class.getResource(path);
  52. if (imgURL != null) {
  53. return new ImageIcon(imgURL, description);
  54. } else {
  55. System.err.println("Couldn't find file: " + path);
  56. return null;
  57. }
  58. }
  59.  
  60. private void showButtonDemo(){
  61.  
  62. headerLabel.setText("Good game and Have fun ;)");
  63.  
  64. //resources folder should be inside SWING folder.
  65. ImageIcon icon = new ImageIcon("exit_test.png");
  66. ImageIcon ExitIcon = new ImageIcon(getClass().getResource("/com/tutorialspoint/gui/images/" + "exit_test.png"));
  67.  
  68.  
  69. // JButton chooseButton = new JButton("Choose Background");
  70. JButton ExitButton = new JButton(ExitIcon);
  71. ExitButton.setPreferredSize(new Dimension(300,100));
  72. // JButton AboutButton = new JButton("About");
  73. // JButton SingleButton = new JButton("Single Player");
  74. // JButton MultyButton = new JButton("Multy Player", icon);
  75. // JButton ControlsButton = new JButton("Controls", icon);
  76. // ControlsButton.setHorizontalTextPosition(SwingConstants.LEFT);
  77. //
  78. ExitButton.addActionListener(new ActionListener() {
  79. public void actionPerformed(ActionEvent e) {
  80. statusLabel.setText("Exit Button clicked.");
  81. statusLabel.setAlignmentX(100);
  82. statusLabel.setAlignmentY(30);
  83. }
  84. });
  85. //
  86. // AboutButton.addActionListener(new ActionListener() {
  87. // public void actionPerformed(ActionEvent e) {
  88. // statusLabel.setText("About Button clicked.");
  89. // }
  90. // });
  91. //
  92. // SingleButton.addActionListener(new ActionListener() {
  93. // public void actionPerformed(ActionEvent e) {
  94. // statusLabel.setText("Single Player Button clicked.");
  95. // }
  96. // });
  97. //
  98. // MultyButton.addActionListener(new ActionListener() {
  99. // public void actionPerformed(ActionEvent e) {
  100. // statusLabel.setText("Multy Player Button clicked.");
  101. // }
  102. // });
  103. //
  104. // ControlsButton.addActionListener(new ActionListener() {
  105. // public void actionPerformed(ActionEvent e) {
  106. // statusLabel.setText("Control Button clicked.");
  107. // }
  108. // });
  109. //
  110. // chooseButton.addActionListener(new ActionListener() {
  111. // public void actionPerformed(ActionEvent e) {
  112. // Color backgroundColor = JColorChooser.showDialog(mainFrame,
  113. // "Choose background color", Color.ORANGE);
  114. // if(backgroundColor != null){
  115. // controlPanel.setBackground(backgroundColor);
  116. // mainFrame.getContentPane().setBackground(backgroundColor);
  117. // }
  118. // }
  119. // });
  120. //
  121. //
  122. // controlPanel.add(chooseButton);
  123. controlPanel.add(ExitButton);
  124. // controlPanel.add(AboutButton);
  125. // controlPanel.add(SingleButton);
  126. // controlPanel.add(MultyButton);
  127. // controlPanel.add(ControlsButton);
  128.  
  129.  
  130. mainFrame.setVisible(true);
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement