GUIMainpublic class GUIMain extends Frame implements WindowListener, ActionListener, TextListener
Fields Summary |
---|
public static boolean | stoppit | TextField | popText | TextField | lengthText | TextField | alphabetText | TextField | alphabetString | TextField | repText | TextField | crossText | TextField | mutText | TextField | maxGenText | Button | pushButton | Button | stopButton | public static TextField | gensStatusScreen | public static TextField | fitnessStatusScreen | public static TextField | bestStatusScreen | int | M | int | L | int | G | float | Pc | float | Pr | float | Pm |
Constructors Summary |
---|
public GUIMain(String s)
super(s);
//setBackground(Color.white);
stoppit=false;
addWindowListener(this);
setLayout(new GridLayout(10,2));
Label popLabel = new Label("Population Size (M)");
add(popLabel);
popText = new TextField("100",5);
add(popText);
popText.addActionListener(this);
Label lengthLabel = new Label("String Length (L)");
add(lengthLabel);
lengthText = new TextField("18",3);
add(lengthText);
lengthText.addActionListener(this);
Label maxGenLabel = new Label("Maximum Generations (G)");
add(maxGenLabel);
maxGenText=new TextField("200",3);
add(maxGenText);
maxGenText.addActionListener(this);
/***********
Label alphabetLabel = new Label("Alphabet Size (K)");
add(alphabetLabel);
alphabetText = new TextField("2",2);
add(alphabetText);
************/
/******************
Label alphabetStringLabel = new Label("Alphabet String");
add(alphabetStringLabel);
alphabetString = new TextField("01",10);
add(alphabetString);
*************************/
Label repLabel = new Label("Reproduction Probability %");
add(repLabel);
repText = new TextField("80",3);
add(repText);
repText.addTextListener(this);
Label crossLabel = new Label("Crossover Probability %");
add(crossLabel);
crossText = new TextField("17",3);
add(crossText);
crossText.addTextListener(this);
Label mutLabel = new Label("Mutation Probability %");
add(mutLabel);
mutText = new TextField("3",3);
add(mutText);
mutText.addTextListener(this);
pushButton = new Button("Go!");
add(pushButton);
pushButton.addActionListener(this);
stopButton = new Button("Stop");
add(stopButton);
stopButton.addActionListener(this);
Label fitLabel=new Label("Fitness");
add(fitLabel);
//status screen display
fitnessStatusScreen = new TextField(20);
fitnessStatusScreen.setEditable(false);
add(fitnessStatusScreen);
Label gensLabel=new Label("Gens %");
add(gensLabel);
gensStatusScreen = new TextField(5);
gensStatusScreen.setEditable(false);
add(gensStatusScreen);
Label bestLabel=new Label("Best individual");
add(bestLabel);
bestStatusScreen=new TextField(L);
bestStatusScreen.setEditable(false);
add(bestStatusScreen);
|
Methods Summary |
---|
public void | actionPerformed(java.awt.event.ActionEvent event)
// Collects button command from data and does some validation
// Sort out source of command
if(event.getSource() == stopButton) {
stoppit=true;
}
if(event.getSource() == popText) {
M = Integer.parseInt(popText.getText());
System.out.println("M String is " + popText.getText());
System.out.println("M Value is " + M);
}
if(event.getSource()==lengthText) {
L= Integer.parseInt(lengthText.getText());
System.out.println("L Value is " + L);
}
if(event.getSource()==maxGenText) {
G = Integer.parseInt(lengthText.getText());
System.out.print("G value is " + G);
}
if(event.getSource()==pushButton) {
//Collect data explicitly, or else it won't be there!
M = Integer.parseInt(popText.getText());
L= Integer.parseInt(lengthText.getText());
G= Integer.parseInt(maxGenText.getText());
int PrPerCent = Integer.parseInt(repText.getText());
Pr = (float)(PrPerCent);
int PcPerCent=Integer.parseInt(crossText.getText());
Pc = (float)(PcPerCent);
int PmPerCent = Integer.parseInt(mutText.getText());
Pm = (float)PmPerCent;
//run the program
System.out.println("Running!!! with M and L"+M+L);
GARunModule.runGA(M,L,G,Pr,Pc,Pm);
}
| public static void | displayBest(java.lang.String s)
bestStatusScreen.setText(s);
| public static void | displayFit(java.lang.String s) // mutation probability
// for status window
fitnessStatusScreen.setText(s);
| public static void | displayGens(java.lang.String s)
gensStatusScreen.setText(s);
| public void | textValueChanged(java.awt.event.TextEvent event)
// The idea here is that the rep, cross and mut probs as 5 always add
// up to 100.
int PrPerCent =Integer.parseInt(repText.getText());
int PcPerCent = Integer.parseInt(crossText.getText());
int PmPerCent=Integer.parseInt(mutText.getText());
try {
if(event.getSource()==repText) {
PrPerCent = Integer.parseInt(repText.getText());
Pr = (float)(PrPerCent);
if(PrPerCent>100) {
PrPerCent=100;
repText.setText(String.valueOf(PrPerCent));
}
if(PrPerCent+PcPerCent+PmPerCent != 100) {
PcPerCent=100-PrPerCent;
crossText.setText(String.valueOf(PcPerCent));
PmPerCent=0;
mutText.setText(String.valueOf(PmPerCent));
}
System.out.println(Pr);
}
if(event.getSource()==crossText) {
PcPerCent=Integer.parseInt(crossText.getText());
if(PcPerCent>100) {
PcPerCent=100;
crossText.setText(String.valueOf(PcPerCent));
}
if(PrPerCent+PcPerCent+PmPerCent>100) {
// PcPerCent=100-PrPerCent;
// crossText.setText(String.valueOf(PcPerCent));
PmPerCent=0;
mutText.setText(String.valueOf(PmPerCent));
}
if(PrPerCent+PcPerCent+PmPerCent<100) {
PmPerCent = 100-PrPerCent-PcPerCent;
mutText.setText(String.valueOf(PmPerCent));
}
Pc = (float)(PcPerCent);
System.out.println("Value is "+Pc);
}
if(event.getSource()==mutText) {
PmPerCent=Integer.parseInt(mutText.getText());
if(PmPerCent>100) {
PmPerCent=100;
mutText.setText(String.valueOf(PmPerCent));
}
if(PrPerCent+PcPerCent+PmPerCent > 100) {
PcPerCent=PcPerCent-PmPerCent;
crossText.setText(String.valueOf(PcPerCent));
// PmPerCent=100-PrPerCent-PmPerCent;
mutText.setText(String.valueOf(PmPerCent));
}
Pm = (float)(PmPerCent);
System.out.println("Value is "+ Pm);
}
}
catch (NumberFormatException e) {}
| public void | windowActivated(java.awt.event.WindowEvent event)
| public void | windowClosed(java.awt.event.WindowEvent event)
| public void | windowClosing(java.awt.event.WindowEvent event)
System.exit(0);
| public void | windowDeactivated(java.awt.event.WindowEvent event)
| public void | windowDeiconified(java.awt.event.WindowEvent event)
| public void | windowIconified(java.awt.event.WindowEvent event)
| public void | windowOpened(java.awt.event.WindowEvent event)
|
|