I am trying to make a storyboard program, but I am having trouble displaying the currect amount of windows per page.
my basic program looks like this
[] = button to open editor
[+] = add new button
[>] = next page
[<] = previous page
Frame
[] [] []
[] [] []
[+] [<] [>]
that is if all of your slots are filled for the first page (6 boards) if you only have 3 then it should look like this
Frame
[] []
[]
[+] [<] [>]
I got this far. my problem is limiting the buttons to 6 per page. Currently when you have 7 windows it looks like this
Frame
[] [] [] []
[] [] []
[+] [<] [>]
and you can keep adding on.
Here is my code
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
public class Frame implements ActionListener{
JFrame frame = new JFrame("Storyboard");
JPanel framePane = new JPanel(new GridLayout (2,3));
Vector<BoardButton> boardButtons = new Vector<BoardButton> ();
JPanel bottomPane = new JPanel (new BorderLayout());
int currentpage = 0; // page number, can only change when there are more then multiples of 6
int pages = 0;
int boards = 0;
JButton next, prev;
public Frame (){
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane ().setPreferredSize(new Dimension (600,400));
frame.pack();
frame.setLayout (new BorderLayout ());
//bottom pane
ImageIcon ico = new ImageIcon ("Images/add.png");
JButton addButton = new JButton(ico);
addButton.setActionCommand("AddBoard");
addButton.addActionListener(this);
next = new JButton (new ImageIcon ("Images/right_arrow.png"));
next.setActionCommand("next");
next.addActionListener(this);
prev = new JButton (new ImageIcon ("Images/left_arrow.png"));
prev.setActionCommand("prev");
prev.addActionListener(this);
JPanel newPanel = new JPanel ();
newPanel.add(prev);
newPanel.add(next);
bottomPane.add(newPanel, BorderLayout.CENTER);
bottomPane.add (addButton, BorderLayout.WEST);
frame.add(bottomPane, BorderLayout.SOUTH);
frame.add(framePane);
addBoardsToFrame();
updateButtons();
frame.setVisible(true);
}
public void addBoardsToFrame (){
framePane.removeAll();
if (boards != 0){
for (int z = 0+(currentpage*6); z < (currentpage*6)+(currentpage*6-boardButtons.size()); z++){
framePane.add(boardButtons.elementAt(z));
}
}
pages = (int)Math.floor(boards/6);
updateButtons ();
frame.validate();
frame.repaint();
System.out.println ("Should Display");
}
private void updateButtons() {
// TODO Auto-generated method stub
pages = (int)Math.floor(boards/6);
if (pages > 0){
next.setEnabled(true);
}
if (currentpage == pages){
next.setEnabled (false);
}
if (currentpage == 0){
prev.setEnabled(false);
}
else {
prev.setEnabled(true);
}
System.out.println ("Current Page: " + currentpage + "\t Pages: " + pages);
frame.validate();
frame.repaint();
}
public void replaceButton (BoardButton boardB){
frame.remove(framePane);
frame.remove(bottomPane);
frame.add (boardButtons.elementAt(boardButtons.indexOf(boardB)).b);
frame.validate();
frame.repaint();
}
public void addBoard(){
System.out.println ("Adding board");
boardButtons.add(new BoardButton(this));
boards += 1;
frame.validate();
addBoardsToFrame();
}
public static void main (String [] args){
Frame f = new Frame ();
}
public void backToButtons (BoardButton.Board board){
frame.remove(board);
frame.add(bottomPane,BorderLayout.SOUTH);
frame.add (framePane);
frame.repaint();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getActionCommand().equals("AddBoard")){
addBoard();
}
if (e.getActionCommand().equals("next")){
currentpage++;
}
if (e.getActionCommand().equals("prev")){
currentpage --;
}
updateButtons ();
}
}
I would like it that when you press next page it displays new buttons, because these will have pictures on them eventually.