public GraphicsUI() { questionPool = new QuestionPool(); setTitle("Question Pool"); setSize(WIDTH, HEIGHT); fileL = new JLabel("Location of Question Pool File:"); fileTF = new JTextField(10); checkB = new JButton("Check File"); log = new JTextArea(6, 30); Container pane = getContentPane(); pane.setLayout(null); // set locations and sizes for the elements fileL.setLocation(90, 15); fileL.setSize(ELEMENT_WIDTH, 30); fileTF.setLocation(90, 65); fileTF.setSize(ELEMENT_WIDTH, 30); checkB.setLocation(90, 105); checkB.setSize(300, 35); log.setLocation(90, 145); log.setSize(300, 30); // add listener to button CheckButtonHandler cbHandler = new CheckButtonHandler(); checkB.addActionListener(cbHandler); fileTF.addActionListener(cbHandler); // add elements to pane pane.add(fileL); pane.add(fileTF); pane.add(checkB); pane.add(log); setLocation(100, 60); setVisible(true); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }
private void initialize() { panel = new JPanel(); frame = new JFrame(); can.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { PointerInfo a = MouseInfo.getPointerInfo(); Point b = a.getLocation(); double x = b.getX(); double y = b.getY(); System.out.println("Entered x: " + x); System.out.println("Entered y: " + y); if (x == 950) { x = 0; } else if (x < 950) { x = (x / 950) - 1; } else if (x > 950) { x = (x / 950) - 1; } if (y == 563) { y = 0; } else if (y < 563) { y = 1 - (y / 563); } else if (y > 563) { y = 1 - (y / 563); } System.out.println("NEW NEW NEW NEW x: " + x); System.out.println("NEW NEW NEW NEW y: " + y); double inc = -2; var = new ArrayList<Double>(); for (int i = -200; i < 200; i++) { var.add(new Equation(x, y).setEquationReturn(inc)); inc = inc + .01; } double paintInc = -2; for (int dx = 0; dx < 200; dx++) { double dy = var.get(dx); theG.add(new Ellipse2D.Double(0 + paintInc, 540 - dy, 10, 10)); paintInc = paintInc + 10; } /*This is to display the Y values for testing purposes Iterator<Double> it = var.iterator(); while (it.hasNext()){ System.out.println(it.next()); }*/ can.repaint(); } }); JLabel xL = new JLabel(); JLabel yL = new JLabel(); JTextArea a = new JTextArea(); a.setLocation(540, 540); a.setText("FFFFFFFFFFFUCK"); a.setBackground(Color.white); yL.setText("Y"); xL.setText("X"); yL.setLocation(930, 10); yL.setSize(10, 10); yL.setBackground(Color.black); xL.setLocation(1900, 550); xL.setSize(10, 10); xL.setBackground(Color.black); xL.setOpaque(true); yL.setOpaque(true); panel.setBackground(Color.darkGray); can.setBackground(Color.black); can.setForeground(Color.black); frame.getContentPane().add(can); panel.setLayout(new GridLayout(1, 0, 0, 0)); frame.add(xL); frame.add(yL); frame.add(can); frame.setBounds(0, 0, 1920, 1080); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }