Sunday, January 27, 2008

Jan 27

I missed class on Friday, so today I spent a while messing with Java, trying to get a "paint" style application I'm building to do what I want it to. Specifically, I'm attempting to allow the user to have options like brush size and color. I am also having some problems with one bit of code; for some reason I can't get the drawing panel to have a different background from the main frame.

public void createUserInterface()
{
// get content pane for attaching GUI components
Container contentPane = getContentPane();

// enable explicit positioning of GUI components
contentPane.setLayout( null );
contentPane.setBackground(Color.BLACK);

// set up myDrawJPanel
myDrawJPanel = new DrawJPanel2();
myDrawJPanel.setBounds( 150, 8, 350, 274 );
myDrawJPanel.setBackground(Color.WHITE);
contentPane.add( myDrawJPanel );

// set properties of application's window
setTitle( "Painter" ); // set title bar text
setSize( 516, 330 ); // set window size
setVisible( true ); // display window

} // end method createUserInterface

As far as I know, this should give a black window with a white panel to the right side, but the panel is black too. Oh well.

No comments: