ProjektGraph/OurApplication/OurMethodButtons.java

77 lines
1.8 KiB
Java

package OurApplication;
import visualisation.ParameterArea;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* This class extends visualisation.ParameterArea to provide a panel for selecting
* algorithmic methods such as Djikstra or A-Star.
*
* @see ParameterArea
*/
public class OurMethodButtons extends ParameterArea {
private static final long serialVersionUID = 1L;
protected JRadioButton button1;
protected JRadioButton button2;
private boolean isDjikstra;
/** TextField containing maximum sum up value. */
protected JTextField maxValue;
/**
* Standard constructor.
* Initializes the method buttons panel with default settings.
*/
public OurMethodButtons() {
super();
isDjikstra = true; // Default to Djikstra
// Set layout manager to arrange buttons vertically
setLayout(new GridLayout(1, 2, 5, 5)); // 1 row, 2 columns, 5 pixels gap
// Create radio buttons
button1 = new JRadioButton("Djikstra", true);
button2 = new JRadioButton("A-Stern");
// Create a button group and add buttons to ensure mutual exclusion
ButtonGroup group = new ButtonGroup();
group.add(button1);
group.add(button2);
// Add action listeners to handle button selections
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
isDjikstra = true;
}
});
button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
isDjikstra = false;
}
});
// Add buttons to the panel
this.add(button1);
this.add(button2);
}
/**
* Retrieves the selected algorithmic method.
*
* @return true if Djikstra is selected, false if A-Star is selected
*/
public boolean getSelectedMethod() {
return isDjikstra;
}
}