ProjektGraph/OurApplication/OurMethodButtons.java

77 lines
1.8 KiB
Java
Raw Normal View History

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