import java.awt.*; import java.awt.event.*; import java.lang.Math; import java.lang.Object; import java.util.Vector; public class Genetics extends java.applet.Applet implements ActionListener { int currentGen = 0; //Stuff for interface Graph currentGraph; Graph barGraph; Graph lineGraph; Panel topPanel, parameters; Button forwardButton; Button backButton; Button enterValuesButton; Button toggleGraphButton; Button showValuesButton; Button showGraphButton; Label allele0Label, allele1Label; Label selfac0Label, selfac1Label, selfac2Label; FrameWindow InputWindow; String alleleLabels[] = new String[2]; //Stuff for Generation final int numGenerations = 100; Generation gen[] = new Generation[numGenerations]; //Layout Stuff TextArea textOutput; int current_layout; static final int GRAPHLAYOUT = 1; static final int TEXT_LAYOUT = 2; static final int BASELENGTH = 12; static final int FIELDLENGTH = 14; static String spaces[] = new String[35]; public void init() { InputWindow = new FrameWindow("Basic Information Input", this); InputWindow.setSize(450,500); forwardButton = new Button("->"); backButton = new Button("<-"); enterValuesButton = new Button("Enter Values"); toggleGraphButton = new Button("Toggle Graph Type"); showValuesButton = new Button("Show Values"); showGraphButton = new Button("Work with Graph"); forwardButton.addActionListener(this); backButton.addActionListener(this); enterValuesButton.addActionListener(this); toggleGraphButton.addActionListener(this); showValuesButton.addActionListener(this); showGraphButton.addActionListener(this); spaces[0] = new String(""); spaces[1] = new String(" "); spaces[2] = new String(" "); spaces[3] = new String(" "); spaces[4] = new String(" "); spaces[5] = new String(" "); spaces[6] = new String(" "); spaces[7] = new String(" "); spaces[8] = new String(" "); spaces[9] = new String(" "); spaces[10] = new String(" "); spaces[11] = new String(" "); spaces[12] = new String(" "); spaces[13] = new String(" "); spaces[14] = new String(" "); spaces[15] = new String(" "); spaces[16] = new String(" "); spaces[17] = new String(" "); spaces[18] = new String(" "); spaces[19] = new String(" "); spaces[20] = new String(" "); spaces[21] = new String(" "); spaces[22] = new String(" "); spaces[23] = new String(" "); spaces[24] = new String(" "); spaces[25] = new String(" "); spaces[26] = new String(" "); spaces[27] = new String(" "); spaces[28] = new String(" "); spaces[29] = new String(" "); spaces[30] = new String(" "); spaces[31] = new String(" "); spaces[32] = new String(" "); spaces[33] = new String(" "); spaces[34] = new String(" "); ChangeLayout(GRAPHLAYOUT); } public void ChangeLayout(int new_layout) { current_layout = new_layout; if (GRAPHLAYOUT == current_layout) { System.out.println("Changing to Graph Layout"); setGraphLayout(); } else { System.out.println("Changing to TEXT Layout"); setTextLayout(); } } public void setGraphLayout() { removeAll(); setLayout(new BorderLayout()); if (topPanel == null) { topPanel = new Panel(); topPanel.setLayout(new GridLayout(1,5)); topPanel.add(backButton); topPanel.add(enterValuesButton); topPanel.add(toggleGraphButton); topPanel.add(showValuesButton); showValuesButton.setEnabled(false); // Do not let the use view the output values // until the input window has been filled in. topPanel.add(forwardButton); topPanel.doLayout(); } add ("North", topPanel); if (null == lineGraph) { lineGraph = new Graph(20, 450, 400, 400, 10, 1, 2, 1); currentGraph = lineGraph; } if (null == barGraph) { barGraph = new Graph(20, 450, 400, 400, 10, 1, 3, 0); currentGraph = barGraph; } if (currentGraph == barGraph) { add("Center", barGraph); } else if (currentGraph == lineGraph) { add("Center", lineGraph); } if (parameters == null) { if (InputWindow != null) { parameters = new Panel(); parameters.setLayout(new GridLayout(2, 5)); parameters.add(new Label("Initial Allele Frequencies :")); allele0Label = new Label(" 50"); parameters.add(allele0Label); allele1Label = new Label(" 50"); parameters.add(allele1Label); parameters.add(new Label(" ")); parameters.add(new Label("Selection Factors")); selfac0Label = new Label(" 50"); parameters.add(selfac0Label); selfac1Label = new Label(" 50"); parameters.add(selfac1Label); selfac2Label = new Label(" 50"); parameters.add(selfac2Label); parameters.doLayout(); } } add ("South", parameters); setBackground(Color.lightGray); doLayout(); repaint(); } public void setTextLayout() { StringBuffer outputBuf; String outputString = null; String nullString; removeAll(); setLayout(new BorderLayout()); if (null == textOutput) { textOutput = new TextArea(105, 80); textOutput.setEditable(false); textOutput.setFont(new Font("Courier", java.awt.Font.PLAIN, 12) ); } add("Center", textOutput); //textOutput.setText(""); //outputString = new String("Generation\tAllele Frequencies\tGenotype Frequencies\n"); outputBuf = new StringBuffer("Generation"); outputBuf.append(new String(spaces[BASELENGTH - outputBuf.length()]) ); outputBuf.append("Allele Frequencies"); outputBuf.append(new String(spaces[BASELENGTH + 2 * FIELDLENGTH - outputBuf.length()]) ); outputBuf.append("Genotype Frequencies\n"); //textOutput.appendText(new String(outputBuf) ); textOutput.setText(new String(outputBuf) ); //outputString = new String("\t\tA\tB\tAA\tAB\tBB\n"); //outputBuf = new StringBuffer(""); outputBuf = new StringBuffer(new String(spaces[BASELENGTH])); outputBuf.append(InputWindow.textfield2.getText() ); outputBuf.append( new String(spaces[BASELENGTH + FIELDLENGTH - outputBuf.length() ])); outputBuf.append(InputWindow.textfield4.getText() ); outputBuf.append( new String(spaces[BASELENGTH + 2 * FIELDLENGTH - outputBuf.length() ])); outputBuf.append(InputWindow.textfield7.getText() ); outputBuf.append( new String(spaces[BASELENGTH + 3 * FIELDLENGTH - outputBuf.length() ])); outputBuf.append(InputWindow.textfield10.getText() ); outputBuf.append( new String(spaces[BASELENGTH + 4 * FIELDLENGTH - outputBuf.length() ])); outputBuf.append(InputWindow.textfield13.getText() + "\n" ); textOutput.append(new String(outputBuf) ); for (int i=0; i 0) c.insets = new Insets(top, left, bottom, right); ((GridBagLayout)container.getLayout()).setConstraints(component, c); container.add(component); } public void adjustmentValueChanged(AdjustmentEvent e) { int i; Object sourceObj = e.getSource(); if (sourceObj instanceof Scrollbar) { if (((Scrollbar)sourceObj).equals(Allele_freq_scroll)) { repaint(); return; } /* endif -- Allele frequency scrollbar was adjusted */ for (i = 1; i < 4; i++) { if (((Scrollbar)sourceObj).equals(genotype_scroll[i])) { repaint(); return; } } /* endfor -- i */ return; } /* endif -- A scrollbar was adjusted */ } // end processEvent() public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof Button) { if ( ((Button)e.getSource()).equals(okay)) { this.hide(); myParent.allele0Label.setText( textfield2.getText() + " " + allele_freq_one_label.getText()); myParent.allele1Label.setText( textfield4.getText() + " " + allele_freq_two_label.getText()); myParent.selfac0Label.setText( textfield7.getText() + " " + genotype_sel_factor_label[1].getText()); myParent.selfac1Label.setText( textfield10.getText() + " " + genotype_sel_factor_label[2].getText()); myParent.selfac2Label.setText( textfield13.getText() + " " + genotype_sel_factor_label[3].getText()); myParent.runSimulation(); return; } // endif -- the okay button was pushed } // the event was a button press } // end actionPerformed public void getValues(float init_frequency[], float selection_factor[], String genotype_description[], String allele_description[]) { int i; for(i=0; i<2; i++) init_frequency[i] = init_freq[i]; for(i=0; i<3; i++) selection_factor[i] = sel_factor[i]; genotype_description[0] = textfield7.getText(); genotype_description[1] = textfield10.getText(); genotype_description[2] = textfield13.getText(); allele_description[0] = textfield2.getText(); allele_description[1] = textfield4.getText(); } public void paint(Graphics g) { int i; for (i = 1; i < 4; i++) { genotype_sel_factor_label[i].setText(Integer.toString(100 - genotype_scroll[i].getValue() ) ); sel_factor[i-1] = (float) (100 - genotype_scroll[i].getValue()); } allele_freq_one_label.setText(Integer.toString( 100 - Allele_freq_scroll.getValue() ) ); init_freq[0] = (float)(( 100 - Allele_freq_scroll.getValue()) / 100.0 ); allele_freq_two_label.setText(Integer.toString( Allele_freq_scroll.getValue() ) ); init_freq[1] = (float)((Allele_freq_scroll.getValue() ) / 100.0); super.paint(g); } }