Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab_03;
- import java.awt.BorderLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.Vector;
- import javax.swing.ComboBoxModel;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JList;
- import javax.swing.JPanel;
- import javax.swing.JSplitPane;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.event.*;
- import java.util.*;
- public class BoardFrame extends JFrame implements ActionListener {
- Board board;
- int sizeOfBoard = -1;
- int winner = 5;
- String x = "X";
- String o = "O";
- private static final long serialVersionUID = 1L;
- JButton exitButton = new JButton("Exit");
- JLabel strategyLabel = new JLabel("Strategy:");
- JLabel levelLabel = new JLabel("Dificculty Level:");
- JList<String> loadedStratedyList = new JList<String>();
- Vector<Loader> vectorClass = new Vector<Loader>();
- Vector<JButton> buttonVector = new Vector<JButton>();
- JPanel panel = new JPanel();
- JPanel panelBoard = new JPanel();
- JComboBox<String> strategyComboBox;
- JComboBox<String> levelComboBox;
- public BoardFrame(int size,Vector<String> loadedStratedyList,Vector<String> loadedLevelList) {
- JSplitPane splitPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panel, panelBoard);
- strategyComboBox = new JComboBox<String>(loadedStratedyList);
- levelComboBox = new JComboBox<String>(loadedLevelList);
- sizeOfBoard = size;
- exitButton.addActionListener(this);
- strategyComboBox.addActionListener(this);
- levelComboBox.addActionListener(this);
- setContentPane(splitPanel);
- panel.add(strategyLabel);
- panel.add(strategyComboBox);
- panel.add(levelLabel);
- panel.add(levelComboBox);
- panel.add(exitButton);
- for(int i = 0; i < size;i++ ) {
- for(int j =0; j < size; j++) {
- buttonVector.addElement(new JButton(" "));
- }
- }
- panelBoard.setLayout(new GridLayout(sizeOfBoard, sizeOfBoard));
- for(int i = 0; i < size;i++ ) {
- for(int j = 0; j < size; j++) {
- buttonVector.get(j*size+i).addActionListener(this);
- panelBoard.add(buttonVector.get(j*size+i));
- }
- }
- splitPanel.setResizeWeight(0.5);
- splitPanel.setOneTouchExpandable(true);
- splitPanel.setContinuousLayout(true);
- setDefaultCloseOperation(DISPOSE_ON_CLOSE);
- setSize(600,650);
- this.setVisible(true);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- Object source = e.getSource();
- for(int i = 0 ;i <(sizeOfBoard*sizeOfBoard); i++ ) {
- if(source == buttonVector.get(i)) {
- buttonVector.get(i).setText(x);
- //board.move(i, x);
- }
- }
- if(source == exitButton) {
- }
- }
- }
Add Comment
Please, Sign In to add comment