Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import javax.swing.border.Border;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class Main {
- public static void main(String[] args){
- Window window = new Window();
- }
- }
- /**
- * Created by user on 27.05.15.
- */
- public class Window extends JFrame {
- public Window() {
- initUI();
- }
- private void initUI() {
- setLayout(null);
- createMenu();
- createInfoPanel();
- setTitle("Szachy");
- setSize(800, 600);
- setLocationRelativeTo(null);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- getContentPane().setBackground(Color.lightGray);
- setVisible(true);
- }
- private void createMenu(){
- JMenuBar menubar = new JMenuBar();
- JMenu gra = new JMenu("Gra");
- JMenu gracz = new JMenu("Gracz");
- JMenu pomoc = new JMenu("Pomoc");
- JMenuItem nowaGra = new JMenuItem("Nowa gra");
- nowaGra.setToolTipText("Rozpocznij nową grę");
- JMenuItem ranking = new JMenuItem("Ranking");
- JMenuItem wyjscie = new JMenuItem("Wyjście");
- wyjscie.setToolTipText("Wyjście z aplikacji");
- wyjscie.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent event) {
- System.exit(0);
- }
- });
- JMenuItem mojProfil = new JMenuItem("Mój profil");
- JMenuItem wyloguj = new JMenuItem("Wyloguj");
- JMenuItem ustawienia = new JMenuItem("Ustawienia");
- ustawienia.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent actionEvent) {
- JFrame jFrameUstawienia = new JFrame("Ustawienia");
- jFrameUstawienia.setSize(400,300);
- jFrameUstawienia.setLocationRelativeTo(null);
- jFrameUstawienia.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
- jFrameUstawienia.getContentPane().setBackground(Color.lightGray);
- jFrameUstawienia.setVisible(true);
- JCheckBox jCheckBox1 = new JCheckBox("JCheckBox1");
- JCheckBox jCheckBox2 = new JCheckBox("JCheckBox2");
- JCheckBox jCheckBox3 = new JCheckBox("JCheckBox3");
- jCheckBox1.setBackground(Color.lightGray);
- jCheckBox2.setBackground(Color.lightGray);
- jCheckBox3.setBackground(Color.lightGray);
- JComboBox jComboBox = new JComboBox();
- jComboBox.addItem("Lorem");
- jComboBox.addItem("ipsum");
- jComboBox.addItem("dolor");
- jComboBox.addItem("sit amet\n");
- jComboBox.addItem("amet\n");
- JButton jButton = new JButton("button");
- jButton.setBackground(Color.lightGray);
- jFrameUstawienia.setLayout(new FlowLayout());
- jFrameUstawienia.add(jCheckBox1);
- jFrameUstawienia.add(jCheckBox2);
- jFrameUstawienia.add(jCheckBox3);
- jFrameUstawienia.add(jComboBox);
- jFrameUstawienia.add(jButton);
- }
- });
- JMenuItem pomocMenuItem = new JMenuItem("Pomoc");
- pomocMenuItem.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent actionEvent) {
- JFrame jFramePomoc = new JFrame("Pomoc");
- jFramePomoc.setSize(400, 300);
- jFramePomoc.setLocationRelativeTo(null);
- jFramePomoc.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
- jFramePomoc.getContentPane().setBackground(Color.lightGray);
- jFramePomoc.setVisible(true);
- JLabel jLabelPomoc1 = new JLabel("Lorem ipsum dolor sit amet, consectetur");
- JLabel jLabelPomoc2 = new JLabel("adipiscing elit. Morbi id hendrerit ");
- JLabel jLabelPomoc3 = new JLabel("dui, nec auctor velit. Pellentesque");
- JLabel jLabelPomoc4 = new JLabel("facilisis suscipit commodo. Donec.");
- jFramePomoc.add(jLabelPomoc1);
- jFramePomoc.add(jLabelPomoc2);
- jFramePomoc.add(jLabelPomoc3);
- jFramePomoc.add(jLabelPomoc4);
- jFramePomoc.setLayout(new FlowLayout());
- }
- });
- gra.add(nowaGra);
- gra.add(ranking);
- gra.add(wyjscie);
- gracz.add(mojProfil);
- gracz.add(wyloguj);
- pomoc.add(ustawienia);
- pomoc.add(pomocMenuItem);
- menubar.add(gra);
- menubar.add(gracz);
- menubar.add(pomoc);
- setJMenuBar(menubar);
- }
- private void createInfoPanel(){
- JLabel label = new JLabel(" Gracz1 : 00:00:00");
- Border border = BorderFactory.createLineBorder(Color.darkGray, 1);
- label.setBorder(border);
- label.setBounds(580,150,150,50);
- add(label);
- JLabel label2 = new JLabel(" Gracz2 : 00:00:00");
- Border border2 = BorderFactory.createLineBorder(Color.darkGray, 3);
- label2.setBorder(border2);
- label2.setBounds(580,350,150,50);
- add(label2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement