Hi,
I have devised the following class. It has no errors but for some reason only an empty box appears when I run it. Why? I am providing the code below- if anyone has any ideas please let me know.
import javax.swing.JFrame;
import javax.swing.JComboBox;
import javax.swing.JRadioButton;
import javax.swing.JPanel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ButtonGroup;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class clusterFormationOptions {
public static void main(String[] args) {
optionsFrame frame = new optionsFrame();
frame.setTitle("Cluster Formation Options");
frame.show();
}
}
class optionsFrame extends JFrame{
public optionsFrame(){
final int DEFAULT_FRAME_WIDTH = 300;
final int DEFAULT_FRAME_HEIGHT = 300;
setSize(DEFAULT_FRAME_WIDTH,DEFAULT_FRAME_HEIGHT);
optionsListener listener = new optionsListener();
automatedButton = new JRadioButton("Automated");
automatedButton.setSelected(true);
automatedButton.addActionListener(listener);
agglomerativeButton = new JRadioButton("Agglomerative");
agglomerativeButton.setSelected(true);
agglomerativeButton.addActionListener(listener);
divisiveButton = new JRadioButton("Divisive");
divisiveButton.setSelected(true);
divisiveButton.addActionListener(listener);
ButtonGroup clusteringGroup = new ButtonGroup();
clusteringGroup.add(automatedButton);
clusteringGroup.add(agglomerativeButton);
clusteringGroup.add(divisiveButton);
cutOffCombo = new JComboBox();
cutOffCombo.addItem("1");
cutOffCombo.addItem("2");
cutOffCombo.addItem("3");
cutOffCombo.addItem("4");
cutOffCombo.addItem("5");
cutOffCombo.addItem("6");
cutOffCombo.addItem("7");
cutOffCombo.addItem("8");
cutOffCombo.addItem("9");
cutOffCombo.addItem("10");
cutOffCombo.addItem("11");
cutOffCombo.addItem("12");
cutOffCombo.addItem("13");
cutOffCombo.addItem("14");
cutOffCombo.addItem("15");
cutOffCombo.addItem("16");
cutOffCombo.addItem("17");
cutOffCombo.addItem("18");
cutOffCombo.addItem("19");
cutOffCombo.addItem("20");
JPanel clusteringGroupPanel = new JPanel();
clusteringGroupPanel.add(automatedButton);
clusteringGroupPanel.add(agglomerativeButton);
clusteringGroupPanel.add(divisiveButton);
clusteringGroupPanel.setBorder (new TitledBorder(new EtchedBorder(), "Select" +
"method for clustering"));
JPanel cutOffComboPanel=new JPanel();
cutOffComboPanel.add(cutOffCombo);
cutOffComboPanel.setBorder (new TitledBorder(new EtchedBorder(), "Select" +
"cut-off point"));
JPanel theBox = new JPanel();
theBox.add(clusteringGroupPanel);
theBox.add(cutOffComboPanel);
getChoice();
}
public void getChoice(){
String divisive1 = null;
String agglomerative1 = null;
String automated1 = null;
//gets all the users choices to be used for the data mining
String cutOff = (String)cutOffCombo.getSelectedItem();
//gets the type of clustering requested by the user
final String AUTOMATED = automated1;
final String AGGLOMERATIVE = agglomerative1;
final String DIVISIVE = divisive1;
String clusteringMethod = "null";
if(automatedButton.isSelected())
clusteringMethod = AUTOMATED;
if (agglomerativeButton.isSelected())
clusteringMethod = AGGLOMERATIVE;
if (divisiveButton.isSelected())
clusteringMethod = DIVISIVE;
}
private JRadioButton automatedButton;
private JRadioButton agglomerativeButton;
private JRadioButton divisiveButton;
private JComboBox cutOffCombo;
private class optionsListener implements ActionListener{
public void actionPerformed (ActionEvent event){
getChoice();
}
}
/*private class WindowCloser extends WindowAdapter{
public void windowClosing(WindowEvent event){
System.exit(0);
}}*/
}
I have devised the following class. It has no errors but for some reason only an empty box appears when I run it. Why? I am providing the code below- if anyone has any ideas please let me know.
import javax.swing.JFrame;
import javax.swing.JComboBox;
import javax.swing.JRadioButton;
import javax.swing.JPanel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ButtonGroup;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class clusterFormationOptions {
public static void main(String[] args) {
optionsFrame frame = new optionsFrame();
frame.setTitle("Cluster Formation Options");
frame.show();
}
}
class optionsFrame extends JFrame{
public optionsFrame(){
final int DEFAULT_FRAME_WIDTH = 300;
final int DEFAULT_FRAME_HEIGHT = 300;
setSize(DEFAULT_FRAME_WIDTH,DEFAULT_FRAME_HEIGHT);
optionsListener listener = new optionsListener();
automatedButton = new JRadioButton("Automated");
automatedButton.setSelected(true);
automatedButton.addActionListener(listener);
agglomerativeButton = new JRadioButton("Agglomerative");
agglomerativeButton.setSelected(true);
agglomerativeButton.addActionListener(listener);
divisiveButton = new JRadioButton("Divisive");
divisiveButton.setSelected(true);
divisiveButton.addActionListener(listener);
ButtonGroup clusteringGroup = new ButtonGroup();
clusteringGroup.add(automatedButton);
clusteringGroup.add(agglomerativeButton);
clusteringGroup.add(divisiveButton);
cutOffCombo = new JComboBox();
cutOffCombo.addItem("1");
cutOffCombo.addItem("2");
cutOffCombo.addItem("3");
cutOffCombo.addItem("4");
cutOffCombo.addItem("5");
cutOffCombo.addItem("6");
cutOffCombo.addItem("7");
cutOffCombo.addItem("8");
cutOffCombo.addItem("9");
cutOffCombo.addItem("10");
cutOffCombo.addItem("11");
cutOffCombo.addItem("12");
cutOffCombo.addItem("13");
cutOffCombo.addItem("14");
cutOffCombo.addItem("15");
cutOffCombo.addItem("16");
cutOffCombo.addItem("17");
cutOffCombo.addItem("18");
cutOffCombo.addItem("19");
cutOffCombo.addItem("20");
JPanel clusteringGroupPanel = new JPanel();
clusteringGroupPanel.add(automatedButton);
clusteringGroupPanel.add(agglomerativeButton);
clusteringGroupPanel.add(divisiveButton);
clusteringGroupPanel.setBorder (new TitledBorder(new EtchedBorder(), "Select" +
"method for clustering"));
JPanel cutOffComboPanel=new JPanel();
cutOffComboPanel.add(cutOffCombo);
cutOffComboPanel.setBorder (new TitledBorder(new EtchedBorder(), "Select" +
"cut-off point"));
JPanel theBox = new JPanel();
theBox.add(clusteringGroupPanel);
theBox.add(cutOffComboPanel);
getChoice();
}
public void getChoice(){
String divisive1 = null;
String agglomerative1 = null;
String automated1 = null;
//gets all the users choices to be used for the data mining
String cutOff = (String)cutOffCombo.getSelectedItem();
//gets the type of clustering requested by the user
final String AUTOMATED = automated1;
final String AGGLOMERATIVE = agglomerative1;
final String DIVISIVE = divisive1;
String clusteringMethod = "null";
if(automatedButton.isSelected())
clusteringMethod = AUTOMATED;
if (agglomerativeButton.isSelected())
clusteringMethod = AGGLOMERATIVE;
if (divisiveButton.isSelected())
clusteringMethod = DIVISIVE;
}
private JRadioButton automatedButton;
private JRadioButton agglomerativeButton;
private JRadioButton divisiveButton;
private JComboBox cutOffCombo;
private class optionsListener implements ActionListener{
public void actionPerformed (ActionEvent event){
getChoice();
}
}
/*private class WindowCloser extends WindowAdapter{
public void windowClosing(WindowEvent event){
System.exit(0);
}}*/
}