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

  • Home
  • SEARCH
  • 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 98873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:16:46+00:00 2026-05-11T00:16:46+00:00

I have the points by the end of the GenerateButton class but now that

  • 0

I have the points by the end of the GenerateButton class but now that I got my public double[][] matrix with all the points in, where do I begin drawing them???

my Main.java:

import java.awt.*; import javax.swing.*;  public class Main {      public static Display display = new Display();       public static void main(String[] args) {          display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         display.setVisible(true);      } } 

my Display.java:

import java.awt.*; import java.awt.event.*; import java.awt.dnd.*; import java.util.Vector;  import javax.swing.*;  public class Display extends JFrame {     final int FRAME_WIDTH = 910;     final int FRAME_HEIGHT = 660;     final int X_OFFSET = 40;     final int Y_OFFSET = 40;      final int GRAPH_OFFSETX = 15;     final int GRAPH_OFFSETY = 40;     final int GRAPH_WIDTH = 500;     final int GRAPH_HEIGHT = 500;     final int GRAPH_INTERVAL = 20;      JButton submit;     JTextField numPoint;     JPanel bpanel;     JPanel points;     Vector<JTextField> pointsA = new Vector<JTextField>();     int maxPoints;     public double[][] matrix;      public Display() {         init();     }      public void init() {         setBackground(Color.WHITE);         setLocation(X_OFFSET, Y_OFFSET);         setSize(FRAME_WIDTH, FRAME_HEIGHT);         setTitle('Geometric Transformations');         getContentPane().setLayout(null);         setDefaultLookAndFeelDecorated(true);          numPoint = new JTextField();         numPoint.setText('# Points?');         numPoint.setBounds(530,200,120+20,25);          SubmitButton submit = new SubmitButton('Submit');         submit.setBounds(530+150, 200, 100, 25);          GenerateButton submitC = new GenerateButton('Generate');         submitC.setBounds(530-5, 200+130, 100, 25);          points = new JPanel(new GridLayout(2,2));         points.setBounds(530, 200+40,100+270,80);          this.add(numPoint);         this.add(submit);         this.add(submitC);         this.add(points, BorderLayout.LINE_START);          repaint();     }      public void paint(Graphics g) {         super.paint(g);         g.setColor(Color.WHITE);         g.fillRect(100, 100, 20, 30);         g.setColor(Color.BLACK);         genGraph(g, GRAPH_OFFSETX, GRAPH_OFFSETY,                  GRAPH_WIDTH, GRAPH_HEIGHT, GRAPH_INTERVAL);     }      public void genGraph (Graphics g, int x, int y,                           int width, int height, int interval) {         // draw background         int border = 5;         g.setColor(Color.BLACK);         width = width - (width % interval);         height = height - (height % interval);         for (int col=x; col <= x+width; col+=interval) {             g.drawLine(col, y, col, y+height);         }         for (int row=y; row <= y+height; row+=interval) {             g.drawLine(x, row, x+width, row);         }     }     class SubmitButton extends JButton implements ActionListener {          public SubmitButton(String title){             super(title);             addActionListener(this);         }         public void actionPerformed (ActionEvent e) {             maxPoints = Integer.parseInt(numPoint.getText()) * 2;              points.removeAll();        // clear JPanel so results from last aren't appended to                                 // delete this line and first enter 2 then 10 for # points             for (int i=0; i<maxPoints; i++) {                 JTextField textField = new JTextField();                 points.add(textField);        // add to JPanel that gets displayed                 pointsA.add(textField);        // for getting values from later             }              matrix = new double[2][pointsA.size()/2];       // setting up dimension of matrix double[][]              points.validate();             points.repaint();              // What to Check:             // Things between commas are either spaces (which will be stripped later)             // or numbers!              // Pairs must match up!         }     }     class GenerateButton extends JButton implements ActionListener {         public GenerateButton (String title) {             super(title);             addActionListener(this);         }         public void actionPerformed (ActionEvent e) {             int c=0;             for (int i=0; i<pointsA.size()/2; i++) {                 JTextField pointTF = pointsA.get(i);                 Double point = Double.parseDouble(pointTF.getText());                 matrix[0][c] = point;                 c++;             }             c=0;             for (int i=pointsA.size()/2; i<pointsA.size(); i++) {                 JTextField pointTF = pointsA.get(i);                 Double point = Double.parseDouble(pointTF.getText());                 matrix[1][c] = point;                 c++;             }             for (int i=0; i<matrix.length; i++) {                 for (int j=0; j<matrix[0].length; j++) {                     System.out.println('i:'+i+'\t'+'j:'+j);                     System.out.println('      '+matrix[i][j]);                 }             }         }     } } 
  • 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. 2026-05-11T00:16:47+00:00Added an answer on May 11, 2026 at 12:16 am

    I’m not quite exactly sure what you are asking. Normally, you put all of the drawing functionality in the paint() method. However, you generally want to keep any long running work off of the AWT dispatch thread which is the same thread that your buttons’ actionPerformed() method is invoked on. To keep your program responsive, you may want to delegate it to a SwingWorker.

    If your app is not being shown, it is likely because you have not called pack() and show() (in that order) during your JPanel’s initialization. Generally, you should do this as the last thing in your init() method. Adding components afterward or changing your components state anywhere but in the AWT thread after this may cause AWT to get mad at you and throw an exception.

    If you are asking how to draw the points themselves, you should look into Graphics.drawPolyline() and the related methods, which you should call from within your paint() method.

    If you’re asking how to draw them from within the button handler, you don’t. You call repaint() and let the object repaint itself on its own time. Also, in your case, I wouldn’t bother subclasing JButton. Just implement actionListener. In you init() method, just create two buttons and register your listeners with them. This also means that you don’t have to override their constructors.

    Also, you mask submit during your init() method: it is never referenced and neither is bpanel. Also, I would use a separate X and Y array rather than trying to combine them into a single matrix. You don’t need to declare matrix to be public since the inner classes can already see it anyway. In fact, you can (and probably should) declare all of the fields to be private. You also have way too many magic numbers floating around and you are fighting Swing way too much: just let it do it’s job laying all your stuff out. You should also try show the smallest possible problem that will allow us to answer your problem: this one sort of flows all over the place and is hard to follow.

    Oh, and the real reason why your lines are not being drawn: you call repaint on your JPanel and not the JFrame that you want to draw on. If you just call repaint() instead of points.repaint() the JFrame will take care of drawing itself and all of its children.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer My experience is that in situations where you need a… May 11, 2026 at 2:20 pm
  • added an answer You cannot have different indexes for the different lists. When… May 11, 2026 at 2:19 pm
  • added an answer If it's really 'Open Source' (as opposed to merely free),… May 11, 2026 at 2:19 pm

Related Questions

I have a large number of 2D points and I want to quickly get
I'm trying to chart the number of registrations per day in our registration system.
I have a map defined like this std::map<some_key_type, std::string::iterator> mIteratorMap; And a huge string
I have a line that I draw in a window and I let the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.