New to Java Need help with Basic Graphic program

Hello all,

I am starting to write a Basic Graphic program for a College JAVA course that will draw simple shapes (Oval and Rectangle) when the respective button is pushed.  Now I already have the design set up with the buttons I need.  These include the two mentioned earlier and a "Center" button as well as a "Corner" button.  These will either draw the shape (which ever is selected) in the Center or all 4 corners of the Display Panel.  I also already have three classes which are: DisplayPanel, ButtonPanel, and ButtonInterfaceApplication.

My question is this:  How do I get DisplayPanel class to correctly display the shapes and layout?  Meaning I click the button which registers in the ButtonPanel class and the DisplayPanel class will read the information from that class and do what is necessary.

I know that I should use Boolean expressions for the 4 buttons.  But I am confused on tieing it all together.  Mainly method calling and the interface aspect.  I already know how to draw the shapes with the Graphics g thing.

Thanks for any help at all.
bigred1022Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
have a read of this to get you started:

http://www.ictp.trieste.it/~manuals/programming/Java/tutorial/uiswing/painting/drawingShapes.html

give me a yell when u get stuck
0
Manikandan ThiagarajanSenior consultantCommented:
0
bigred1022Author Commented:
Both suggestions are greatly appreciated but not what I am looking for exactly.  here is some of my code that I already have:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class ButtonPanel extends JPanel implements ActionListener{
   private  JButton jbCircle;
   private  JButton jbSquare;
   
    /** Creates a new instance of ButtonPanel */
    public ButtonPanel() {
        jbCircle = new JButton("Circle");
        jbSquare = new JButton("Square");
        jbCenter = new JButton("Center");
        jbCorner = new JButton("Corner");
        jbCircle.addActionListener(this);
        jbSquare.addActionListener(this);
        jbCenter.addActionListener(this);
        jbCorner.addActionListener(this);
        add(jbCircle);
        add(jbSquare);
        add(jbCenter);
        add(jbCorner);
       
    }

    public void actionPerformed(ActionEvent e) {
        System.out.println("A button was Clicked....");
    }
   
Now Instead of the Println command I need the program to do what the button says.  Should I be placing IF statements in the actionPerformed? (I.E. IF jbCircle(true) then draw).  I am unsure of what to write in order for the DisplayPanel to do the requested operation.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

objectsCommented:
you need to add a paintComponent() method to your panel (or the panel you want to paint your shapes on).
Also member vars to store the details of the actual shapes to paint.
0
bigred1022Author Commented:
This is from my DisplayPanel class:

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

public class DisplayPanel extends JPanel {
   
    /** Creates a new instance of DisplayPanel */
    public DisplayPanel() {
    }

    public void paintComponent(Graphics g) {

        super.paintComponent(g);
             
    }

Now I know that you would write something like g.drawOval(2, 3, 45, 50) and g.drawRect(2, 2, 2, 2)
But I don't know How to code the classes in order for them to basically "see" each other.  I click a button and the DisplayPanel draws.  But how?  I know I am making this sound tougher than it is.
0
Manikandan ThiagarajanSenior consultantCommented:
public void actionPerformed(ActionEvent e) {
       if(e.getSource() == jbCircle )
{

       repaint();// this repaint would call the public void paintComponent(Graphics g)



    }


}

  public void paintComponent(Graphics g) {

        super.paintComponent(g);

// do some painting here
             
    }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Manikandan ThiagarajanSenior consultantCommented:
glad to help you, reason for b grade
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.