I'm making a paint program for my end of the year project and my teacher has no idea how to do graphics/apps, so i was wondering if anyone here could tell me the proper way to add a button with a color changing ability? (I'd assume add an action listener that sets color, but that hasn't been working). My main issue is whenever i do get a button successfully in the program, it covers up my drawing area so it is just a button and the drawing doesn't work. It just draws by making lots of small vectors.
Here is the code (Sorry if i'm adding it wrong)
You need to separate out the different areas of your GUI into separate panels. Don't paint on the content pane, use it to hold the panels that you will put your components on. The default layout manager is a FlowLayout, which places the panel's contents in a row. You need to set the layout manager to a BorderLayout if you want use the Borderlayout options. The recommended way to do this is to create a new panel, set its layout to the one you want, and set it in the frame as the new content pane. This is explained here.
Subclass a JPanel for the drawing and put your paint method and the mouse listener there (remember to call the superclass paint method before adding your own paint code in the paint method). Add your painting panel to the middle of the frame with BorderLayout.CENTER (you don't actually need to do it via the content pane, you can add it directly to the frame - it handles adding it to the content pane for you). Set the preferred size of the painting panel to what you would like.
Add your button to the south of the frame (preferably put it in its own panel).
Don't use Vector unless you're multi-threading, use ArrayList instead, it works the same, but it's more efficient.