Creating a program/ game with numbered colored blocks. It has three classes eventually four. Using lists, panel, and mush more problem is that i dont get any output from one of my classes. Its probably a novice mistake but hey im a novice so i will make those mistakes. So please just take a look at the code and give me a hand.
thanks in advance.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Assignment1 extends Applet {
// Constants
private static final Color defaultTopColor = Color.red;
private static final Color defaultMiddleColor = Color.yellow;
private static final Color defaultBottomColor = Color.blue;
private static final String RED = "Red";
private static final String YELLOW = "Yellow";
private static final String BLUE = "Blue";
private static final String RESET = "Reset";
private static final String TOP_LIST_LABEL = "Top Row Colors";
private static final String MIDDLE_LIST_LABEL = "Middle Row Colors";
private static final String BOTTOM_LIST_LABEL = "Bottom Row Colors";
// Variables
private Panel mainPanel, boardPanel, listsPanel;
private Board board;
private Button resetButton;
private List topRowColorList, middleRowColorList, bottomRowColorList;
public void init() {
// initializes applet
this.makeMainPanel();
}
private List makeColorList(int itemNumber){
// Creates Lists with 3 colour options; preselects the item with the given itemNumber
List listMaker = new List(itemNumber);
listMaker.add(RED);
listMaker.add(YELLOW);
listMaker.add(BLUE);
return listMaker;
}
private Panel makeListsPanel() {
// Makes Labels and Lists for row colour choices, then adds them to a Panel
listsPanel = new Panel(new GridLayout(2,3));
Label label1 = new Label(TOP_LIST_LABEL);
Label label2 = new Label(MIDDLE_LIST_LABEL);
Label label3 = new Label(BOTTOM_LIST_LABEL);
topRowColorList = makeColorList(1);
middleRowColorList = makeColorList(2);
bottomRowColorList = makeColorList(3);
listsPanel.add(label1);
listsPanel.add(topRowColorList);
listsPanel.add(label2);
listsPanel.add(middleRowColorList);
listsPanel.add(label3);
listsPanel.add(bottomRowColorList);
return listsPanel;
}
private Panel makeBoardPanel() {
// Creates a Board using the default row colours, creates a reset Button;
Board board = new Board(defaultTopColor,defaultMiddleColor,defaultBottomColor);
resetButton = new Button(RESET);
boardPanel = new Panel(new FlowLayout());
boardPanel.add(board);
boardPanel.add(resetButton);
return boardPanel;
}
private Panel makeMainPanel() {
// creates and returns the Panel which contains the boardPanel and the ListsPanel
makeBoardPanel();
makeListsPanel();
mainPanel = new Panel(new GridLayout(2,1));
mainPanel.add(boardPanel);
mainPanel.add(listsPanel);
return mainPanel;
}
}// end of class
shouldnt calling the makemainpanel() method in the public void init(){
shouldnt this display on the screen?
thanks in advance again
thanks in advance.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Assignment1 extends Applet {
// Constants
private static final Color defaultTopColor = Color.red;
private static final Color defaultMiddleColor = Color.yellow;
private static final Color defaultBottomColor = Color.blue;
private static final String RED = "Red";
private static final String YELLOW = "Yellow";
private static final String BLUE = "Blue";
private static final String RESET = "Reset";
private static final String TOP_LIST_LABEL = "Top Row Colors";
private static final String MIDDLE_LIST_LABEL = "Middle Row Colors";
private static final String BOTTOM_LIST_LABEL = "Bottom Row Colors";
// Variables
private Panel mainPanel, boardPanel, listsPanel;
private Board board;
private Button resetButton;
private List topRowColorList, middleRowColorList, bottomRowColorList;
public void init() {
// initializes applet
this.makeMainPanel();
}
private List makeColorList(int itemNumber){
// Creates Lists with 3 colour options; preselects the item with the given itemNumber
List listMaker = new List(itemNumber);
listMaker.add(RED);
listMaker.add(YELLOW);
listMaker.add(BLUE);
return listMaker;
}
private Panel makeListsPanel() {
// Makes Labels and Lists for row colour choices, then adds them to a Panel
listsPanel = new Panel(new GridLayout(2,3));
Label label1 = new Label(TOP_LIST_LABEL);
Label label2 = new Label(MIDDLE_LIST_LABEL);
Label label3 = new Label(BOTTOM_LIST_LABEL);
topRowColorList = makeColorList(1);
middleRowColorList = makeColorList(2);
bottomRowColorList = makeColorList(3);
listsPanel.add(label1);
listsPanel.add(topRowColorList);
listsPanel.add(label2);
listsPanel.add(middleRowColorList);
listsPanel.add(label3);
listsPanel.add(bottomRowColorList);
return listsPanel;
}
private Panel makeBoardPanel() {
// Creates a Board using the default row colours, creates a reset Button;
Board board = new Board(defaultTopColor,defaultMiddleColor,defaultBottomColor);
resetButton = new Button(RESET);
boardPanel = new Panel(new FlowLayout());
boardPanel.add(board);
boardPanel.add(resetButton);
return boardPanel;
}
private Panel makeMainPanel() {
// creates and returns the Panel which contains the boardPanel and the ListsPanel
makeBoardPanel();
makeListsPanel();
mainPanel = new Panel(new GridLayout(2,1));
mainPanel.add(boardPanel);
mainPanel.add(listsPanel);
return mainPanel;
}
}// end of class
shouldnt calling the makemainpanel() method in the public void init(){
shouldnt this display on the screen?
thanks in advance again