Advertisement
Guest User

Untitled

a guest
May 28th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.31 KB | None | 0 0
  1. import javax.swing.*;
  2. import javax.swing.border.Border;
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args){
  10.         Window window = new Window();
  11.     }
  12.  
  13. }
  14.  
  15.  
  16. /**
  17.  * Created by user on 27.05.15.
  18.  */
  19. public class Window extends JFrame {
  20.  
  21.     public Window() {
  22.         initUI();
  23.  
  24.     }
  25.  
  26.     private void initUI() {
  27.         setLayout(null);
  28.         createMenu();
  29.         createInfoPanel();
  30.         setTitle("Szachy");
  31.         setSize(800, 600);
  32.         setLocationRelativeTo(null);
  33.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  34.         getContentPane().setBackground(Color.lightGray);
  35.         setVisible(true);
  36.     }
  37.  
  38.     private void createMenu(){
  39.  
  40.         JMenuBar menubar = new JMenuBar();
  41.  
  42.         JMenu gra = new JMenu("Gra");
  43.         JMenu gracz = new JMenu("Gracz");
  44.         JMenu pomoc = new JMenu("Pomoc");
  45.  
  46.         JMenuItem nowaGra = new JMenuItem("Nowa gra");
  47.         nowaGra.setToolTipText("Rozpocznij nową grę");
  48.  
  49.         JMenuItem ranking = new JMenuItem("Ranking");
  50.  
  51.         JMenuItem wyjscie = new JMenuItem("Wyjście");
  52.         wyjscie.setToolTipText("Wyjście z aplikacji");
  53.         wyjscie.addActionListener(new ActionListener() {
  54.             @Override
  55.             public void actionPerformed(ActionEvent event) {
  56.                 System.exit(0);
  57.             }
  58.         });
  59.  
  60.         JMenuItem mojProfil = new JMenuItem("Mój profil");
  61.         JMenuItem wyloguj = new JMenuItem("Wyloguj");
  62.  
  63.         JMenuItem ustawienia = new JMenuItem("Ustawienia");
  64.         ustawienia.addActionListener(new ActionListener() {
  65.             @Override
  66.             public void actionPerformed(ActionEvent actionEvent) {
  67.                 JFrame jFrameUstawienia = new JFrame("Ustawienia");
  68.                 jFrameUstawienia.setSize(400,300);
  69.                 jFrameUstawienia.setLocationRelativeTo(null);
  70.                 jFrameUstawienia.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  71.                 jFrameUstawienia.getContentPane().setBackground(Color.lightGray);
  72.                 jFrameUstawienia.setVisible(true);
  73.  
  74.                 JCheckBox jCheckBox1 = new JCheckBox("JCheckBox1");
  75.                 JCheckBox jCheckBox2 = new JCheckBox("JCheckBox2");
  76.                 JCheckBox jCheckBox3 = new JCheckBox("JCheckBox3");
  77.                 jCheckBox1.setBackground(Color.lightGray);
  78.                 jCheckBox2.setBackground(Color.lightGray);
  79.                 jCheckBox3.setBackground(Color.lightGray);
  80.  
  81.                 JComboBox jComboBox = new JComboBox();
  82.                 jComboBox.addItem("Lorem");
  83.                 jComboBox.addItem("ipsum");
  84.                 jComboBox.addItem("dolor");
  85.                 jComboBox.addItem("sit amet\n");
  86.                 jComboBox.addItem("amet\n");
  87.  
  88.                 JButton jButton = new JButton("button");
  89.                 jButton.setBackground(Color.lightGray);
  90.  
  91.                 jFrameUstawienia.setLayout(new FlowLayout());
  92.                 jFrameUstawienia.add(jCheckBox1);
  93.                 jFrameUstawienia.add(jCheckBox2);
  94.                 jFrameUstawienia.add(jCheckBox3);
  95.                 jFrameUstawienia.add(jComboBox);
  96.                 jFrameUstawienia.add(jButton);
  97.  
  98.             }
  99.         });
  100.  
  101.         JMenuItem pomocMenuItem = new JMenuItem("Pomoc");
  102.         pomocMenuItem.addActionListener(new ActionListener() {
  103.             @Override
  104.             public void actionPerformed(ActionEvent actionEvent) {
  105.                 JFrame jFramePomoc = new JFrame("Pomoc");
  106.                 jFramePomoc.setSize(400, 300);
  107.                 jFramePomoc.setLocationRelativeTo(null);
  108.                 jFramePomoc.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  109.                 jFramePomoc.getContentPane().setBackground(Color.lightGray);
  110.                 jFramePomoc.setVisible(true);
  111.  
  112.                 JLabel jLabelPomoc1 = new JLabel("Lorem ipsum dolor sit amet, consectetur");
  113.                 JLabel jLabelPomoc2 = new JLabel("adipiscing elit. Morbi id hendrerit ");
  114.                 JLabel jLabelPomoc3 = new JLabel("dui, nec auctor velit. Pellentesque");
  115.                 JLabel jLabelPomoc4 = new JLabel("facilisis suscipit commodo. Donec.");
  116.  
  117.                 jFramePomoc.add(jLabelPomoc1);
  118.                 jFramePomoc.add(jLabelPomoc2);
  119.                 jFramePomoc.add(jLabelPomoc3);
  120.                 jFramePomoc.add(jLabelPomoc4);
  121.  
  122.                 jFramePomoc.setLayout(new FlowLayout());
  123.  
  124.             }
  125.         });
  126.  
  127.         gra.add(nowaGra);
  128.         gra.add(ranking);
  129.         gra.add(wyjscie);
  130.         gracz.add(mojProfil);
  131.         gracz.add(wyloguj);
  132.         pomoc.add(ustawienia);
  133.         pomoc.add(pomocMenuItem);
  134.         menubar.add(gra);
  135.         menubar.add(gracz);
  136.         menubar.add(pomoc);
  137.  
  138.         setJMenuBar(menubar);
  139.     }
  140.  
  141.    
  142.  
  143.  
  144.     private void createInfoPanel(){
  145.         JLabel label = new JLabel(" Gracz1  :  00:00:00");
  146.  
  147.         Border border = BorderFactory.createLineBorder(Color.darkGray, 1);
  148.         label.setBorder(border);
  149.         label.setBounds(580,150,150,50);
  150.         add(label);
  151.  
  152.         JLabel label2 = new JLabel(" Gracz2  :  00:00:00");
  153.  
  154.         Border border2 = BorderFactory.createLineBorder(Color.darkGray, 3);
  155.         label2.setBorder(border2);
  156.         label2.setBounds(580,350,150,50);
  157.         add(label2);
  158.     }
  159.  
  160.  
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement