Hi i need to add crosshairs to my code, like draw 2 lines across the screen on a JPanel, i also need to be able to turn them on and off with a checkbox which is on a JPanel. the other panel needs to be drawable on like a paint program. But even if I could get the crosshairs working it would be a huge help.
//import classes
import javax.swing.*;
import java.awt.*;
import java.awt.Paint;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class v2 extends JFrame { //class name
public static void main(String[] args) // start of main method
{
jane();
}
public static void jane()
{
//make frame
Frame f1 = new JFrame();
f1.setVisible(true);
f1.setTitle("Mirror Draw");
f1.setSize(640, 480);
f1.setAlwaysOnTop(true);
f1.setLocation(100, 100); //this code sets where the Jframe appears when the program is run
// f1.setResizable(false);
JPanel contentPane = new JPanel(); //create panel
contentPane.setSize(480, 480);
contentPane.setBackground(Color.LIGHT_GRAY);
//contentPane.setLocation(0, 0);
//contentPane.setLayout(null); //this allows me to place items wherever I want in the panel
//f1.add(contentPane); //add content pane(Panel) to JFrame
JPanel buttonPane = new JPanel();
buttonPane.setBackground(Color.RED);
buttonPane.setLocation(480, 0);
buttonPane.setSize(160, 480);
//f1.add(buttonPane);
JButton btnHorizonal = new JButton("Horizontal Mirroring");
btnHorizonal.setVisible(true);
btnHorizonal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
JButton btnVertical = new JButton("Vertical Mirroring ");
btnVertical.setVisible(true);
btnVertical.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
JButton btnDiagonal = new JButton("Diagonal Mirroring ");
btnDiagonal.setVisible(true);
btnDiagonal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
JButton btnRed = new JButton(" ");
btnRed.setBackground(Color.red);
JButton btnBlue = new JButton(" ");
btnBlue.setBackground(Color.blue);
JButton btnGreen = new JButton(" ");
btnGreen.setBackground(Color.GREEN);
JButton btnBlack = new JButton(" ");
btnBlack.setBackground(Color.BLACK);
JButton btnClear = new JButton("Clear All Drawing");
JCheckBox crossHairs = new JCheckBox("Crosshairs");
buttonPane.add(btnHorizonal);
buttonPane.add(btnVertical);
buttonPane.add(btnDiagonal);
buttonPane.add(btnRed);
buttonPane.add(btnBlue);
buttonPane.add(btnGreen);
buttonPane.add(btnBlack);
buttonPane.add(crossHairs);
buttonPane.add(btnClear);
f1.add(buttonPane);
f1.add(contentPane);
}
}