Advertisement
Mercedes

let's play ;)

Nov 19th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. package missil.command;
  2.  
  3. import static missil.command.MissileComand.getInstance;
  4.  
  5. import java.awt.BorderLayout;
  6. import java.awt.Dimension;
  7. import java.awt.FlowLayout;
  8. import java.awt.Graphics;
  9. import java.awt.GridBagLayout;
  10. import java.awt.Image;
  11. import java.awt.Insets;
  12. import java.awt.event.MouseAdapter;
  13. import java.awt.event.MouseEvent;
  14. import java.net.URL;
  15.  
  16. import javax.swing.ImageIcon;
  17. import javax.swing.JButton;
  18. import javax.swing.JComboBox;
  19. import javax.swing.JFrame;
  20. import javax.swing.JLabel;
  21. import javax.swing.JMenu;
  22. import javax.swing.JMenuBar;
  23. import javax.swing.JPanel;
  24. import javax.swing.JTextField;
  25.  
  26. import java.awt.BorderLayout;
  27. import java.awt.Dimension;
  28. import java.awt.Graphics;
  29. import java.awt.GridBagConstraints;
  30. import java.awt.GridBagLayout;
  31. import java.awt.Image;
  32. import java.awt.Insets;
  33. import java.awt.event.MouseAdapter;
  34. import java.awt.event.MouseEvent;
  35. import java.io.IOException;
  36. import java.net.URL;
  37.  
  38. import javax.imageio.ImageIO;
  39. import javax.swing.ImageIcon;
  40. import javax.swing.JButton;
  41. import javax.swing.JFrame;
  42. import javax.swing.JPanel;
  43. import javax.swing.border.EmptyBorder;
  44.  
  45. import missil.command.PantallaInicial.MiPanel;
  46. import missil.command.Ranking.goBack;
  47.  
  48. public class AJugar extends JFrame {
  49. private JLabel label= new JLabel ("Ingrese su nombre");
  50. private JTextField text= new JTextField (25);
  51. private JButton aceptar = new JButton("Aceptar");
  52. private JButton jugar = new JButton("Jugar");
  53.  
  54. private String nom;
  55. private String level;
  56.  
  57.  
  58.  
  59. private String fondo="recursos/fondoJugar.jpg";
  60.  
  61. private Image imgFondo;
  62. private MiPanel otroPanel;
  63. private static final int ANCHO=1024;
  64. private static final int ALTO=700;
  65.  
  66.  
  67.  
  68. public AJugar(){
  69.  
  70.  
  71. nom=new String();
  72. level=new String();
  73. this.setTitle("Datos del jugador");
  74. JPanel panel= new JPanel(new FlowLayout());
  75. panel.add(label);
  76. panel.add(text);
  77. panel.add(this.aceptar);
  78. panel.add(this.jugar);
  79.  
  80.  
  81. // Valores para el JComboBox
  82. String[] nivelesFruta = {"--Seleccione--","1", "2", "3"
  83. ,"4", "5", "6", "7","8","9","10","11","12","13","14","15","16"}; //son los niveles para selccionar el nombre esta pillo
  84.  
  85. // El primer panel contiene un JLabel y un JCombobox con las frutas
  86. final JPanel comboPanel = new JPanel();
  87. JLabel comboLbl = new JLabel("Nivel: ");
  88. final JComboBox niveles = new JComboBox(nivelesFruta);
  89. niveles.getSelectedItem().toString();
  90. comboPanel.add(comboLbl);
  91. comboPanel.add(niveles);
  92.  
  93. this.add(comboPanel, BorderLayout.WEST);
  94.  
  95.  
  96. // Asegurarse de mostrar el JFrame
  97.  
  98.  
  99.  
  100.  
  101. /* home= new JButton("Atras");
  102. this.home.setVisible(true);
  103. this.add(this.home, BorderLayout.SOUTH);
  104. this.home.addMouseListener(new goBack());
  105. this.setVisible(true); */
  106.  
  107.  
  108.  
  109. /* jugar= new JButton("Jugar");
  110. this.jugar.setVisible(true);
  111. this.add(jugar, BorderLayout.SOUTH); */
  112.  
  113.  
  114.  
  115. this.setSize(ANCHO, ALTO);
  116. otroPanel = new MiPanel();
  117. otroPanel.setLayout(new GridBagLayout());
  118. otroPanel.setPreferredSize(new Dimension(ANCHO,ALTO));
  119.  
  120.  
  121. this.getContentPane().add(panel);
  122.  
  123.  
  124. URL fondoURL = getClass().getClassLoader().getResource(fondo);
  125.  
  126.  
  127. if (fondoURL == null) {
  128. System.err.println("NO SE PUDO CARGAR ALGO: ");
  129. } else {
  130. try {
  131. imgFondo = ImageIO.read(fondoURL);
  132.  
  133.  
  134. } catch (IOException ex) {
  135. ex.printStackTrace();
  136. }
  137. }
  138. GridBagConstraints c = new GridBagConstraints();
  139. c.gridx=0;
  140. c.weighty=100;
  141. c.fill=GridBagConstraints.WEST;
  142. c.gridy=4;
  143. c.gridy=5;
  144. c.gridy=6;
  145. setSize(ANCHO,ALTO);
  146. pack();
  147. this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  148. this.setResizable(false);
  149. this.setExtendedState(MAXIMIZED_BOTH);
  150. setVisible(true);
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. jugar.addMouseListener(new MouseAdapter(){
  159. public void mouseClicked(MouseEvent e){
  160. System.out.println("IMPRIMI SORETE!");
  161. System.out.print("Se presiono el mouse" + text.getText());
  162. nom=text.getText();
  163. getInstance().setNombreDelJugador(nom); //le doy el nombre ingresado lalalala
  164. level=niveles.getSelectedItem().toString();
  165. System.out.print(level);
  166.  
  167. new PantallaDeJuego();}
  168. });
  169.  
  170.  
  171.  
  172.  
  173.  
  174. aceptar.addMouseListener(new MouseAdapter(){
  175. public void mouseClicked( MouseEvent e){
  176.  
  177. /* System.out.print("Se presiono el mouse" + "text.getText()");
  178. nom=text.getText();
  179. getInstance().setNombreDelJugador(nom); //le doy el nombre ingresado lalalala
  180. level=niveles.getSelectedItem().toString();
  181. System.out.print(level); */
  182. }
  183. });
  184.  
  185.  
  186.  
  187. this.setPreferredSize(new Dimension(1024,700));
  188.  
  189.  
  190. this.getContentPane().add(otroPanel);
  191. this.setVisible(true);
  192. }
  193.  
  194.  
  195. public static void main (String args[]){
  196. AJugar j= new AJugar();
  197. j.pack();
  198. j.setVisible(true);
  199.  
  200. }
  201.  
  202.  
  203. public class MiPanel extends JPanel {
  204.  
  205. @Override
  206. public void paintComponent(Graphics arg0) {
  207. super.paintComponent(arg0);
  208. arg0.drawImage(imgFondo, 0, 0, null);
  209. }
  210.  
  211. }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement