Hi,
I really need help with my chess manager program! I work with the MVC principal. My controller class implements ActionListener
Other classes contains JButtons, JTextField.. I have a program it reads a FEN notation and scans it. After that it puts the chess pieces on the board as the FEN describes. I need help with the code, i have to finish this its important for me. Thanks in advance guys!
Controller class:
package controller; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.*; import javax.swing.*; import model.Fen; import view.ControlPanel; import view.InfoPanel; import view.ChessBoardView; public class Controller extends JFrame implements ActionListener { private InfoPanel infopanel; private ControlPanel controlpanel; private Fen fen; private ChessBoardView chessboardview; public Controller() { super("Chess Manager"); makeFrame(); makeMenuBar(); this.pack(); } private void makeFrame(){ setSize(1050, 1050); setDefaultCloseOperation(EXIT_ON_CLOSE); setResizable( false ); Container contentpane = super.getContentPane(); contentpane.setLayout(new BorderLayout()); contentpane.setBackground(new Color(204,229,255)); controlpanel = new ControlPanel(this); contentpane.add(controlpanel, BorderLayout.EAST); infopanel = new InfoPanel(); contentpane.add(infopanel, BorderLayout.SOUTH); chessboardview = new ChessBoardView(); contentpane.add(chessboardview, BorderLayout.WEST); } private void makeMenuBar(){ JMenuBar menubar = new JMenuBar(); super.setJMenuBar(menubar); JMenu fileMenu = new JMenu("File"); menubar.add(fileMenu); JMenu editMenu = new JMenu("Edit"); menubar.add(editMenu); JMenu optionMenu = new JMenu("Options"); menubar.add(optionMenu); JMenu extraMenu = new JMenu("Extra"); menubar.add(extraMenu); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub } }
ControlPanel class:
InfoPanel class:package view; import java.awt.*; import java.awt.event.*; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JSlider; import controller.Controller; import model.ChessBoard; import model.ChessPiece; import model.Fen; import model.Square; import view.ChessBoardView; public class ControlPanel extends JPanel { private JPanel buttonpanel; private JButton btnEmptyBoard, btnInitialPosition; private JSlider sldVolume; private Fen fen; private ChessBoardView chessboardview; private InfoPanel infopanel; public ControlPanel (Controller controller) { setLayout(new GridBagLayout()); setBackground(new Color(204,229,255)); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(10,0,0,30); btnEmptyBoard = new JButton("Empty Board"); gbc.gridy = 0; btnEmptyBoard .setPreferredSize(new Dimension(180, 25)); //btnEmptyBoard .addActionListener(controller); btnEmptyBoard .setRequestFocusEnabled(false); add(btnEmptyBoard, gbc); btnInitialPosition = new JButton("Initial Position"); gbc.gridy =1; btnInitialPosition .setPreferredSize(new Dimension(180, 25)); btnInitialPosition .addActionListener(controller); <<<<<<<<<<<<<< actionlistener with controller parameter btnInitialPosition .setRequestFocusEnabled(false); add(btnInitialPosition, gbc); } public JButton getButton(){ return btnInitialPosition; } }
package view; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JPanel; import javax.swing.JTextPane; import javax.swing.JTextField; import javax.swing.JTextArea; import javax.swing.BorderFactory; import model.Subscription; import model.Fen; import controller.Controller; import view.ChessBoardView; import controller.Controller; public class InfoPanel extends JPanel { private Subscription subscription; private Fen fen; private ChessBoardView chessboardview; private JTextField subscriptionbar; private JTextField fenbar; private JTextArea infobar; public InfoPanel (Controller controller){ setLayout(new GridBagLayout()); setBackground(new Color(204,229,255)); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(10,0,10,0); subscriptionbar = new JTextField(new Subscription().getSubscription()); gbc.gridy = 0; subscriptionbar .setPreferredSize(new Dimension(500, 25)); subscriptionbar .setBorder(BorderFactory.createLineBorder(Color.BLACK)); add(subscriptionbar, gbc); fenbar = new JTextField(new Fen().getFen()); gbc.gridy = 1; fenbar .setPreferredSize(new Dimension(500, 25)); fenbar .setBorder(BorderFactory.createLineBorder(Color.BLACK)); fenbar .addActionListener(controller); add(fenbar, gbc); infobar = new JTextArea(); gbc.gridy = 2; infobar .setPreferredSize(new Dimension(500, 150)); infobar .setBorder(BorderFactory.createLineBorder(Color.BLACK)); infobar .setEditable(false); add(infobar, gbc); } public String getFen(){ return fenbar.getText(); } }
the code has to to something like this
String input = fenbar.getText();
fen.scanner(input);
fen.scanFen();
chessboardview.addSquaresAndPiecesToPanel();
Screen Shot 2013-08-15 at 10.40.19 PM.jpg