Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
how to call paintComponent when button is clicked JavaJDK NetBeans

I want to call paintComponent class just if button is clicked that's using JavaJDK Gui NetBeans

public class KnnJDK extends Application {

    @Override
public void start(Stage primaryStage) {
     Button butt = new Button();
        butt.setText("Applique KPPV");
        grid.add(butt, 0, 5);
     butt.setOnAction(event -> {
         // i want to call it here !

     });
public void paintComponent(Graphics g){ 
         // dessiner les points 
        for (int i =0;i<n;i++)
        {
            g.fillOval(ListX[i], ListY[i], 20, 20);
        }       
        //dessiner les arcs
        for (int i = 0; i <n; i++) {
            for (int j =0;j<n;j++)
            {
                if ((mAdjG[i][j]==1)&&(i!=j)){
                    g.drawLine(ListX [i]+10, ListY [i]+10, ListX [j]+10, ListY [j]+10);
                }
            }
        }
}

How to do that ? thanks for reading and helping

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

just remove this package import javafx.scene.control.Button;

   package knnjdkwithdgr;


  import java.awt.*; 

  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collections;


 public class KnnJDKWithDGR extends Application implements ActionListener{




    public void paint(Graphics g)
  {
  int n = 10;
  int ListX []=new int[n];
  int ListY []=new int[n];
 // dessiner les points 
    for (int i =0;i<n;i++)
    {
        g.fillOval(ListX[i], ListY[i], 20, 20);
    }        
}



@Override

public void start(Stage primaryStage) 
{

    Button buttdgr = new Button();

    buttdgr.addActionListener(this);


 }
  public void actionPerformed(ActionEvent e)
  {

  }

   }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!