martaczaska

Menu_5

Jan 4th, 2020
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.06 KB | None | 0 0
  1. package com.company;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import javax.swing.*;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import javax.swing.JButton;
  10. import javax.swing.JPanel;
  11.  
  12. public class Menu extends JPanel implements ActionListener{
  13.  
  14.     private JButton instrukcja;
  15.     private JButton start;
  16.     private JButton wyjscie;
  17.     public Object poziom;
  18.  
  19.     int w_okno = 1024;
  20.     int h_okno = 768;
  21.     public int time = 1;
  22.  
  23.     public Menu(){
  24.         //setLayout(new GridLayout(3, 1,10, 200));
  25.         setLayout(null);
  26.  
  27.         int WIDTH = 20;
  28.         int HEIGHT = 13;
  29.  
  30.         instrukcja = new JButton("Instrukcja");
  31.         start = new JButton("Start");
  32.         wyjscie = new JButton("Wyjście");
  33.  
  34.         instrukcja.addActionListener(this);
  35.         start.addActionListener(this);
  36.         wyjscie.addActionListener(this);
  37.  
  38.         instrukcja.setBounds(320, 100, 300, 80 );
  39.         start.setBounds(320, 300, 300, 80);
  40.         wyjscie.setBounds(320, 500, 300, 80);
  41.  
  42.         //setPreferredSize(new Dimension(WIDTH, HEIGHT));
  43.         add(instrukcja);
  44.         add(start);
  45.         add(wyjscie);
  46.     }
  47.  
  48.  
  49.     public void actionPerformed(ActionEvent e){
  50.         Object source = e.getSource();
  51.  
  52.         if(source == instrukcja) {
  53.  
  54.             JOptionPane.showMessageDialog(null, "Tutaj będzie cała instrukcja do grania");   //DZIAŁA, NAJS
  55.  
  56.         }
  57.  
  58.         else if(source == start) {
  59.             /*setLayout(new GridLayout(1,1));
  60.             System.out.println("tutaj!");
  61.             Etap_1 e_1 = new Etap_1();
  62.             //add(e_1);
  63.             //add(new Etap_1());
  64.             System.out.println("tutaj też jestem!");
  65.             (new Okno(1024, 768)).add(e_1);*/
  66.  
  67.             Okno noweOkno = new Okno(1024,768);
  68.             CardLayout CL =(CardLayout)(noweOkno.karty.getLayout());
  69.             CL.show(noweOkno.karty, "poziomy");
  70.         }
  71.  
  72.         else if(source == wyjscie){
  73.             System.exit(0);    //DZIAŁA, NAJS
  74.         }
  75.  
  76.     }
  77.  
  78.     //setVisible(true);
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment