Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8500955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:04:54+00:00 2026-06-11T01:04:54+00:00

I am working in a project where I had to draw graph witch includes

  • 0

I am working in a project where I had to draw graph witch includes arrows and nodes!
I made a class that extended JPanel for arrows and the same for the nodes, and I made a JSplitPane to make the menu in the left and the graph in the right! When I add both of the panel, one of them only is visible.

The arrow panel class :

public class ArrowPanel extends JPanel{
int barb;
double phi;
double x1;
double y1;
double x2;
double y2;
double xcentre;
double ycentre;
double x3;
double y3;
double x4;
double y4;

public ArrowPanel(double x1,double y1,double x2, double y2 ,double x3,double y3 ,double x4 ,double y4){
    barb = 30;                   // barb length
    phi = Math.PI/6;             // 30 degrees barb angle
    this.x1=x1;
    this.y1=y1;
    this.x2=x2;
    this.y2=y2;
    this.x3=x3;
    this.y3=y3;
    this.x4=x4;
    this.y4=y4;
    this.setVisible(true);
    this.setOpaque(false)   ;     
        this.setLayout(new GridBagLayout());
        System.out.println(" c est marché");} protected void paintComponent(Graphics g){
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    Graphics2D g3 = (Graphics2D)g;
    g2.setStroke(new BasicStroke(7));
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);
    g3.setStroke(new BasicStroke(7));
    g3.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    int w = getWidth();
    int h = getHeight();
    double theta, x, y;
    double a = 0;
        double b = 0;
        xcentre=(x1 + x2)/2 ;
        ycentre=(y1 + y2)/2 ;
        double z3 = x1;
        double k3 = y1;
        k3=a*z3+b;
        a=(y2-y1)/(x2-x1);
        b=y1-a*x1;
        System.out.println( "a="+ a);
    System.out.println( "b="+ b);
    double a1 = -1/a;
    double b1 = ycentre-a1*xcentre;


    g2.setPaint(Color.RED);
    g3.setPaint(Color.RED);
    g3.draw(new Line2D.Double(x3, y3, x4, y4));
    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    theta = Math.atan2(y2 - y1, x2 - x1);
    double theta2=Math.atan2(y4 - y3, x4 - x3);
    drawArrow(g2, theta, x2, y2);
    drawArrow(g3, theta2, x4, y4);
    g2.setPaint(Color.GREEN);
    g2.draw(new Line2D.Double(xcentre - 5, a*(xcentre - 5)+ b, xcentre+5, a*(xcentre+5)+b));
    g2.drawString("rad1", getX(), getY());
    g2.draw(new Line2D.Double(xcentre - 7, a1*(xcentre - 7)+ b1, xcentre+7, a1*(xcentre+7)+b1));
    xcentre=(x3 + x4)/2 ;
    ycentre=(y3 + y4)/2 ;

         z3 = x3;
         k3 = y3;
        k3=a*z3+b;
        a=(y4-y3)/(x4-x3);
        b=y3-a*x3;
        System.out.println( "a="+ a);
    System.out.println( "b="+ b);
    a1 = -1/a;
    b1 = ycentre-a1*xcentre;
    g3.draw(new Line2D.Double(xcentre - 5, a*(xcentre - 5)+ b, xcentre+5, a*(xcentre+5)+b));
    g3.draw(new Line2D.Double(xcentre - 7, a1*(xcentre - 7)+ b1, xcentre+7, a1*(xcentre+7)+b1));
        System.out.println("bahamas");

}
private void drawArrow(Graphics2D g2, double theta, double x0, double y0)
{
    double x = x0 - barb * Math.cos(theta + phi);
    double y = y0 - barb * Math.sin(theta + phi);
    g2.draw(new Line2D.Double(x0, y0, x, y));
    x = x0 - barb * Math.cos(theta - phi);
    y = y0 - barb * Math.sin(theta - phi);
    g2.draw(new Line2D.Double(x0, y0, x, y));
}}`

This the element class:

public class ElementMenu extends JPanel {private static final long serialVersionUID = 1L;private int largeur;
private Color couleur;
private Color couleurActif;
private Color couleurNormal;
private String texte;
private String Ident;
public ElementMenu(String texte,String Ident, Color couleurNormal, Color couleurActif, int taille) {
    this.couleur=couleurNormal;
    this.couleurNormal=couleurNormal;
    this.couleurActif=couleurActif;
    this.texte=texte;
    this.Ident=Ident ;
    largeur=taille;
    this.setSize(new Dimension(largeur, largeur ));
    this.setOpaque(false);
    this.setLayout(new BorderLayout());
    ajouterListener();
}
private void ajouterListener(){
    addMouseListener(new MouseListener() {public void mouseClicked(MouseEvent e) {}

        public void mouseReleased(MouseEvent e) {}

        public void mousePressed(MouseEvent e) {}

        public void mouseExited(MouseEvent e) {
            couleur=couleurNormal;
            repaint();
        }

        public void mouseEntered(MouseEvent e) {
            couleur=couleurActif;
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            repaint();
        }

    });}public void paint(Graphics arg0) {
    super.paint(arg0);
    Graphics2D g2d = (Graphics2D) arg0;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(couleur);
    g2d.setStroke(new BasicStroke(3));
    GradientPaint gradient = new GradientPaint(largeur / 2, 4, couleur, (largeur) / 2, 4 + largeur, new Color(255,255,255,200));
    g2d.setPaint(gradient);
    g2d.fillOval(4, 4, largeur, largeur);
    gradient = new GradientPaint(largeur / 2, 4, Color.RED, largeur / 2, 4 + largeur / 2, new Color(couleur.getRed(), couleur.getGreen(), couleur.getBlue(), 0));
    g2d.setPaint(gradient);
    g2d.fillOval(4+largeur/5, 4, 5*largeur/8, largeur/3);
    g2d.setColor(Color.WHITE);
    g2d.setFont(new Font("Calibri", Font.BOLD, 14));
    FontMetrics fm = g2d.getFontMetrics();
    int x = 10;
    int y = (fm.getAscent() + (this.getHeight() -
            (fm.getAscent() + fm.getDescent())) / 2 );
    int x0 = (this.getWidth() - fm.stringWidth(Ident)) / 4 +25;
    int y0 = (fm.getAscent() + (this.getHeight() -
            (fm.getAscent() + fm.getDescent())) / 2 -55);
    g2d.drawString(texte, x+15, y);
    g2d.drawString(Ident, x0, y0);}}`

And this the main:

public static void main(String[] args) {
    Fenetre splitPaneTest1 = new Fenetre();
    splitPaneTest1.setSize(1000,600);
    splitPaneTest1.show();
    List<ElementMenu> items = new ArrayList<ElementMenu>();
    items.add(new ElementMenu("rad1","ACTION", new Color(19, 73, 140), new Color(162, 198, 232), 150));
    items.add(new ElementMenu("rad2","GOAL",new Color(19, 73, 140), new Color(162, 198, 232), 150));
    items.add(new ElementMenu("rad3","KNOWLEDGE", new Color(19, 73, 140), new Color(162, 198, 232), 150));
    splitPaneTest1.getContentPane().add(jSplitPane1, BorderLayout.CENTER);
    jSplitPane1.setOpaque(false);
    jSplitPane1.add(new MenuCirculaire(Color.blue, 800, 600, 200, 150,items),JSplitPane.RIGHT);
    jSplitPane1.add(new ArrowPanel(363.5,335,460.5,168,540,171,635.5,335),JSplitPane.RIGHT);
    jSplitPane1.add(new MenuGauche(),JSplitPane.LEFT);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:04:55+00:00Added an answer on June 11, 2026 at 1:04 am

    JSplitPane doesn’t work this way. It only allows one component to be visible in each split section.

    You will need to create another panel which contains both your right-hand-side components. This would look something like:

    JPanel rightPanel = new JPanel(new GridLayout(2, 1));
    rightPanel.add(monMenuCirculaire); 
    rightPanel.add(monArrowPanel);
    jSplitPane1.add(rightPanel, JSplitPane.RIGHT);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on rails project, which had been made using noSql(Mongoid). Every
I was working on project that had problem when encoding UFT-8 text into JSON
I am working on a SVN controlled project that I had checkout from server
I have a web project that had UrlRewriter.NET installed and working fine on .NET
I've been working on a XNA project for a class I'm taking. I had
I am working on a project that I had been compiling with LLVM 2.6
I was working on a project and had my Activities passing each other information
I am working on project of android in eclipse.Android version is 2.3.3. I had
I had a project and everything was working and then for some reasons I
I am working on a project, and had all of my tests passing on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.