Click here to Skip to main content
15,891,033 members
Home / Discussions / Java
   

Java

 
GeneralRe: 5 drawings in 5 rectangular regions within one window Pin
427748024-Oct-09 2:50
427748024-Oct-09 2:50 
GeneralRe: 5 drawings in 5 rectangular regions within one window Pin
WebMaster24-Oct-09 8:10
WebMaster24-Oct-09 8:10 
GeneralRe: 5 drawings in 5 rectangular regions within one window Pin
427748024-Oct-09 8:33
427748024-Oct-09 8:33 
GeneralRe: 5 drawings in 5 rectangular regions within one window Pin
WebMaster24-Oct-09 9:47
WebMaster24-Oct-09 9:47 
GeneralRe: 5 drawings in 5 rectangular regions within one window Pin
427748025-Oct-09 0:05
427748025-Oct-09 0:05 
GeneralRe: 5 drawings in 5 rectangular regions within one window Pin
WebMaster25-Oct-09 2:28
WebMaster25-Oct-09 2:28 
GeneralRe: 5 drawings in 5 rectangular regions within one window Pin
427748025-Oct-09 4:29
427748025-Oct-09 4:29 
QuestionJPanel Field day issues Pin
shawndeprey23-Oct-09 3:46
shawndeprey23-Oct-09 3:46 
I am currently writing a Dungeons & Dragons Session tool for my final project in my Java class. So far I have the GUI drawn up EXCEPT for one ridiculous problem. For three of my JPanels, named panelNorth, PanelSouth, and guiWrapper, I CANNOT seem to set the background color for them. The first block of code is my driver and the second is the gui class for my program. Can anybody see why it will not set the background color for those 3 specific panels???

p.s. the button listened is commented out because I just want to get the gui working before I continue.

Thanks

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

public class ddSessionTool
{
   public static void main (String[] args)
   {
		JFrame frame = new JFrame("Dungeons & Dragons Session Tool");
		frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
		
		JPanel panel = new JPanel();
		panel.setLayout (new BorderLayout());
		panel.setBackground(Color.black);
		panel.setBorder (BorderFactory.createEmptyBorder (8, 8, 8, 8));
		
		Gui gui = new Gui();//the graphical user interface of this program...at least the JPanel part.
		
		panel.add(gui);//ADDS THE GUI TO THE PANEL
		
		frame.getContentPane().add(panel);//ADDS THE GUI TO THE FRAME
		
		frame.pack();
		frame.setSize(600,400);
      frame.setLocation(100,100);
		//frame.setResizable(false);
      frame.setVisible(true);
	}
}


//********************************************************************
//  Gui.java       Author: Shawn Deprey    Date: October 12, 2009
//
//  This class creates the GUI for the D&D Session Tool
//********************************************************************

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

public class Gui extends JPanel
{
   public Gui()
   {
		JPanel guiWrapper = new JPanel();//holds ALL the gui
			guiWrapper.setLayout (new BorderLayout());
			guiWrapper.setBackground(Color.red);
		
		JPanel panelNorth = new JPanel();//this is the top "north" panel.
		JPanel panelSouth = new JPanel();//this is the south panel
		
			JPanel topLeft = new JPanel();//houses enemies stuff
				JPanel topLeftNorth = new JPanel();
				JPanel topLeftCenter = new JPanel();
				JPanel topLeftSouth = new JPanel();
				
			JPanel topRight = new JPanel();//houses the players stuff
				JPanel topRightNorth = new JPanel();
				JPanel topRightCenter = new JPanel();
				JPanel topRightSouth = new JPanel();
				
			JPanel rollerSection = new JPanel();//pick rolers name and supply modifier
			JPanel rollDice = new JPanel();//buttons for rolling dice
			JPanel battleOutput = new JPanel();//list bot with battle output
		
		
		//sets up the buttons
		JButton add1 = new JButton("add");//enemies
		JButton add2 = new JButton("add");//players
		JButton remove1 = new JButton("remove");//enemies
		JButton remove2 = new JButton("remove");//players
		JButton d4 = new JButton("D4");//roll 4 sided di
		JButton d6 = new JButton("D6");//roll 6 sided di
		JButton d8 = new JButton("D8");//roll 8 sided di
		JButton d10 = new JButton("D10");//roll 10 sided di
		JButton d12 = new JButton("D12");//roll 12 sided di
		JButton d20 = new JButton("D20");//roll 20 sided di
		JButton d100 = new JButton("D100");//roll 100 sided di
		
		//sets up Labels tl = top left, tr = top right, bl = bottom label
		JLabel placeHolder = new JLabel("THIS TEST IS A PLACE HOLDER FOR SOMETHING ELSE!!!");
		JLabel tlTitle = new JLabel("Enemies");
			tlTitle.setForeground(Color.white);
		JLabel trTitle = new JLabel("Players");
			trTitle.setForeground(Color.white);
		JLabel blTitle = new JLabel("Battle Area");
			blTitle.setForeground(Color.white);
		JLabel blBattleOutput = new JLabel("Battle Output");
			blBattleOutput.setForeground(Color.white);
		
		//sets up the panel layouts.
		panelNorth.setLayout (new BorderLayout());
			panelNorth.setBackground(Color.black);
		panelSouth.setLayout (new BorderLayout());
			panelSouth.setBackground(Color.black);
		//TOP LEFT SECTION
		topLeft.setLayout (new BorderLayout());
			topLeft.setBorder (BorderFactory.createEmptyBorder (0, 0, 4, 4));
			topLeftNorth.setLayout(new FlowLayout());
				topLeftNorth.setBackground(Color.blue);
			topLeftCenter.setLayout(new FlowLayout());
				topLeftCenter.setBackground(Color.gray);
			topLeftSouth.setLayout(new FlowLayout());
				topLeftSouth.setBackground(Color.gray);
		//TOP RIGHT SECTION	
		topRight.setLayout (new BorderLayout());
			topRight.setBorder (BorderFactory.createEmptyBorder (0, 0, 4, 0));
			topRightNorth.setLayout(new FlowLayout());
				topRightNorth.setBackground(Color.blue);
			topRightCenter.setLayout(new FlowLayout());
				topRightCenter.setBackground(Color.gray);
			topRightSouth.setLayout(new FlowLayout());
				topRightSouth.setBackground(Color.gray);
		//BOTTOM SECTION
		rollerSection.setLayout(new FlowLayout());
			rollerSection.setBackground(Color.blue);
		rollDice.setLayout(new BoxLayout(rollDice, BoxLayout.Y_AXIS));
			rollDice.setBackground(Color.gray);
		battleOutput.setLayout(new BoxLayout(battleOutput, BoxLayout.Y_AXIS));
			battleOutput.setBackground(Color.gray);
			
		//adds elements to the top right and left sections
		topLeftNorth.add(tlTitle);
		topLeftCenter.add(placeHolder);
		topLeftSouth.add(add1);
		topLeftSouth.add(remove1);
		
		topRightNorth.add(trTitle);
		topRightCenter.add(placeHolder);
		topRightSouth.add(add2);
		topRightSouth.add(remove2);
		
		//ads elements to the bottom section
		rollerSection.add(blTitle);
		rollDice.add(d4);
		rollDice.add(d6);
		rollDice.add(d8);
		rollDice.add(d10);
		rollDice.add(d12);
		rollDice.add(d20);
		rollDice.add(d100);
		battleOutput.add(blBattleOutput);
		
		//adds components of the top left and top right section to their respective parent panels
		topLeft.add(topLeftNorth, BorderLayout.NORTH);
		topLeft.add(topLeftCenter, BorderLayout.CENTER);
		topLeft.add(topLeftSouth, BorderLayout.SOUTH);
		topRight.add(topRightNorth, BorderLayout.NORTH);
		topRight.add(topRightCenter, BorderLayout.CENTER);
		topRight.add(topRightSouth, BorderLayout.SOUTH);
		
		//adds sub panels to panelNorth and panelSouth
		panelNorth.add(topLeft, BorderLayout.WEST);
		panelNorth.add(topRight, BorderLayout.EAST);
		panelSouth.add(rollerSection, BorderLayout.NORTH);
		panelSouth.add(rollDice, BorderLayout.WEST);
		panelSouth.add(battleOutput, BorderLayout.CENTER);
		
		guiWrapper.add(panelNorth, BorderLayout.NORTH);
		guiWrapper.add(panelSouth, BorderLayout.SOUTH);
		
		add(guiWrapper, BorderLayout.WEST);
		
	}
	//this button listener will wait for a button to be pressed, and will do certain things if they are pressed.
	/*private class ButtonListener implements ActionListener
	{
   	public void actionPerformed (ActionEvent event)
   	{
      	if(event.getSource() == bRed)
      	{
				setBackground (Color.red);
			}
     		else if(event.getSource() == bWhite)
			{
				setBackground (Color.white);
			}
			else if(event.getSource() == bBlue)
			{
				setBackground (Color.blue);
			}
 	 	}
	}*/
}

AnswerRe: JPanel Field day issues Pin
427748024-Oct-09 0:55
427748024-Oct-09 0:55 
GeneralRe: JPanel Field day issues Pin
shawndeprey24-Oct-09 19:52
shawndeprey24-Oct-09 19:52 
GeneralRe: JPanel Field day issues Pin
427748025-Oct-09 0:10
427748025-Oct-09 0:10 
GeneralRe: JPanel Field day issues Pin
shawndeprey25-Oct-09 4:18
shawndeprey25-Oct-09 4:18 
Questionview page source (of a webpage) Pin
sharkbc22-Oct-09 17:56
sharkbc22-Oct-09 17:56 
AnswerRe: view page source (of a webpage) Pin
427748024-Oct-09 0:58
427748024-Oct-09 0:58 
QuestionWrite a java applet to multiply 2 numbers Pin
Shah Ravi22-Oct-09 17:54
Shah Ravi22-Oct-09 17:54 
AnswerRe: Write a java applet to multiply 2 numbers Pin
Shah Ravi22-Oct-09 18:50
Shah Ravi22-Oct-09 18:50 
AnswerRe: Write a java applet to multiply 2 numbers Pin
Richard MacCutchan23-Oct-09 4:05
mveRichard MacCutchan23-Oct-09 4:05 
AnswerRe: Write a java applet to multiply 2 numbers Pin
shawndeprey23-Oct-09 4:51
shawndeprey23-Oct-09 4:51 
GeneralRe: Write a java applet to multiply 2 numbers Pin
Richard MacCutchan23-Oct-09 5:23
mveRichard MacCutchan23-Oct-09 5:23 
GeneralRe: Write a java applet to multiply 2 numbers Pin
shawndeprey23-Oct-09 16:17
shawndeprey23-Oct-09 16:17 
GeneralRe: Write a java applet to multiply 2 numbers Pin
David Skelly23-Oct-09 6:44
David Skelly23-Oct-09 6:44 
GeneralRe: Write a java applet to multiply 2 numbers Pin
Richard MacCutchan23-Oct-09 6:55
mveRichard MacCutchan23-Oct-09 6:55 
AnswerRe: Write a java applet to multiply 2 numbers Pin
427748024-Oct-09 1:02
427748024-Oct-09 1:02 
Question[Message Deleted] Pin
teknozwizard21-Oct-09 21:03
teknozwizard21-Oct-09 21:03 
AnswerRe: Trouble With Rotating Script Pin
David Skelly21-Oct-09 22:09
David Skelly21-Oct-09 22:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.