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]);
}
}
}
}
}