Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: I Need help with my ActionListener, ActionPerformed and Operations

  1. #1
    Member Wolverine89's Avatar
    Join Date
    Aug 2013
    Location
    Netherlands
    Posts
    101
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I Need help with my ActionListener, ActionPerformed and Operations

    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:
    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;
    		}
    }
    InfoPanel class:
    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
    System.out.println(" dream in code ");


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: I Need help with my ActionListener, ActionPerformed and Operations

    I need help with the code
    The probability of getting help goes up substantially if you ask a specific question. I for one can only guess as to the problem.

Similar Threads

  1. ActionListener inside another ActionListener
    By kpat in forum AWT / Java Swing
    Replies: 6
    Last Post: March 28th, 2012, 03:43 PM
  2. Actionlistener and actionperformed question
    By ms_ceng in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 17th, 2011, 11:59 AM
  3. actionPerformed not returning a value.
    By gher in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 22nd, 2011, 10:15 AM
  4. actionPerformed method
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 4th, 2010, 02:29 AM
  5. actionPerformed
    By Kumarrrr in forum Java Theory & Questions
    Replies: 5
    Last Post: November 23rd, 2010, 09:08 AM