📄 ifscontrol.java
字号:
package leaf;import java.awt.*;import java.awt.event.*;/** * Title: leaf * Description: * Copyright: Copyright (c) 2003 * Company: http://agents.yeah.net * @author keatskk@sina.com * @version 1.0 */public class IFSControl extends Frame { leaf localIFS; TextField txtRule[][]; Button btnDel[]; Button btnMakeRule[]; Panel RulePanel; Label lbl[][]; Label lblRule[]; Label lblP[]; TextField txtP[]; boolean No[]; int NullNumber; double PAddtion=0; int NoRule=0; Label label1 = new Label(); public IFSControl(leaf cl) { super("参数设置"); localIFS=cl; try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { setLayout(new BorderLayout());//定义对齐方式 btnDel = new Button [6]; btnMakeRule = new Button [6]; txtRule = new TextField [6][6]; RulePanel = new Panel(); lbl = new Label [6][6]; lblRule= new Label [6]; lblP =new Label [6]; txtP=new TextField[6]; No= new boolean [6]; Label lblTitle = new Label("定义参数: x'=ax+by+c y'=dx+ey+f 其中每一条规则就是形如这样的一个变换公式"); Label lblTitle2 = new Label(" 需要指定的是变换的系数,P是每条规则出现的概率"); Button btnAdd = new Button("确定"); Button btnCancel = new Button("取消"); Button btnDelAll = new Button("全部清空"); for (int i=0;i<6;i++){ for(int j=0;j<6;j++){ lbl[i][j] = new Label(); txtRule[j][i] = new TextField(2); if (i<localIFS.ruleNumber){ txtRule[j][i].setText(Double.toString(localIFS.rule[j][i])); } else{txtRule[j][i].setText("");} } } for (int i=0;i<6;i++){ btnDel[i] = new Button("清空"+i); btnMakeRule[i] = new Button("制定Rule"+i); lblRule[i]=new Label(); lblP[i]=new Label(); txtP[i]=new TextField(2); if(i<localIFS.ruleNumber){ txtP[i].setText(Double.toString(localIFS.p[i]));} else{txtP[i].setText("");} } for(int i=0;i<6;i++){ lbl[i][0].setText("a:"); lbl[i][1].setText(" b:"); lbl[i][2].setText(" c:"); lbl[i][3].setText(" d:"); lbl[i][4].setText(" e:"); lbl[i][5].setText(" f:"); lblRule[i].setText(" Rule "+i+":"); lblP[i].setText(" P:"); } GridBagLayout layout = new GridBagLayout(); RulePanel.setLayout(layout);// GridBagConstraints constraints = new GridBagConstraints(); constraints.weightx = 0.0; constraints.weighty = 0.0;// constraints.fill = GridBagConstraints.BOTH; constraints.gridwidth = 1; constraints.gridheight = 1; for(int i=0;i<6;i++){ constraints.gridx=0;constraints.gridy=i; layout.setConstraints(btnMakeRule[i],constraints); RulePanel.add(btnMakeRule[i]); constraints.gridx=1;constraints.gridy=i; layout.setConstraints(btnDel[i], constraints); RulePanel.add(btnDel[i]);//,new GridBagConstraints(0,i,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(0,0,0,0),0,0)); constraints.gridx=2;constraints.gridy=i; layout.setConstraints(lblRule[i], constraints); RulePanel.add(lblRule[i]);//,new GridBagConstraints(1,i,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(0,0,0,0),0,0)); for(int j=0;j<6;j++){ constraints.gridx=i*2+3;constraints.gridy=j; layout.setConstraints(lbl[j][i], constraints); RulePanel.add(lbl[j][i]);//,new GridBagConstraints(i*2+2,j,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(0,0,0,0),0,0)); constraints.gridx=i*2+4;constraints.gridy=j; layout.setConstraints(txtRule[i][j], constraints); RulePanel.add(txtRule[i][j]);//,new GridBagConstraints(i*2+3,j,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(0,0,0,0),0,0)); //RulePanel.add(lbl[j]); } constraints.gridx=15;constraints.gridy=i; layout.setConstraints(lblP[i], constraints); RulePanel.add(lblP[i]);//,new GridBagConstraints(14,i,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(0,0,0,0),0,0)); constraints.gridx=16;constraints.gridy=i; layout.setConstraints(txtP[i], constraints); RulePanel.add(txtP[i]);//,new GridBagConstraints(15,i,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(0,0,0,0),0,0)); }/* GridBagLayout layout = new GridBagLayout(); panel.setLayout(layout); GridBagConstraints constraints = new GridBagConstraints(); constraints.weightx = 1.0; constraints.weighty = 1.0; constraints.fill = GridBagConstraints.BOTH; for (i=0;i<11;i++) { constraints.gridwidth = 1; layout.setConstraints(dummiesa[i], constraints); panel.add(dummiesa[i]); constraints.gridwidth = 2; layout.setConstraints(labels[i], constraints); panel.add(labels[i]); constraints.gridwidth = 1; if (i > num-1) { layout.setConstraints(dummiesc[i], constraints); panel.add(dummiesc[i]); } else { layout.setConstraints(choices[i], constraints); panel.add(choices[i]); }*/ this.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(WindowEvent e) { this_windowClosing(e); } }); Panel ButtonPanel = new Panel(); ButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5)); //ButtonPanel.add(lblTitle); label1.setForeground(Color.blue); label1.setText(" 制作:keatskk@sina.com"); ButtonPanel.add(btnAdd); ButtonPanel.add(btnCancel); ButtonPanel.add(btnDelAll); ButtonPanel.add(label1, null); //this.add("North", ButtonPanel); Panel LabelPanel = new Panel(); LabelPanel.setLayout(new BorderLayout()); LabelPanel.add("North",lblTitle); LabelPanel.add("South",lblTitle2); this.add("North",LabelPanel); this.add("South",ButtonPanel); this.add(RulePanel); this.setBackground(Color.white); } void this_windowClosing(WindowEvent e) { localIFS.running=false; localIFS.btnStart.setLabel("开始"); this.hide(); this.dispose(); } public boolean action(Event ev, Object arg){ if ( ev.target instanceof Button) {//instanceof实例 String button = (String) arg; for(int i=0;i<6;i++){ if(ev.target==btnDel[i]){ for(int j=0;j<6;j++){ txtRule[j][i].setText(""); txtP[i].setText(""); } } else if(ev.target==btnMakeRule[i]){ NoRule=i; IFSRule crl=new IFSRule(this); crl.setSize(700,350); crl.show(); } } if (button.equals("全部清空")){ for(int i=0;i<6;i++){ for(int j=0;j<6;j++){ txtRule[i][j].setText(""); } txtP[i].setText(""); } } else if (button.equals("取消")){ localIFS.running=false; localIFS.btnStart.setLabel("开始"); this.hide(); this.dispose(); } else if (button.equals("确定")){ localIFS.rule = new double [6][6]; localIFS.p = new double [6]; localIFS.ruleNumber=6; for(int i=0;i<6;i++){ NullNumber=0; No[i]=true; if (txtP[i].getText().equals("")) txtP[i].setText("0"); localIFS.p[i]=Double.valueOf(txtP[i].getText()).doubleValue(); for(int j=0;j<6;j++){ localIFS.rule[j][i]=0; if (txtRule[j][i].getText().equals("") || Double.valueOf(txtRule[j][i].getText()).doubleValue()==0){ // localIFS.rule[j][i]=0; NullNumber=NullNumber+1; } else{ localIFS.rule[j][i]=Double.valueOf(txtRule[j][i].getText()).doubleValue(); } } if (NullNumber==6){ localIFS.ruleNumber=localIFS.ruleNumber-1; No[i]=false; } } for (int i=0;i<6;i++){ if (No[i]==false){ for(int k=i;k<6;k++){ if(No[k]==true){ for(int j=0;j<6;j++){ localIFS.rule[j][i]=localIFS.rule[j][k]; localIFS.rule[j][k]=0; localIFS.p[i]=localIFS.p[k]; } No[i]=true; No[k]=false; break; } } } } for(int i=0;i<localIFS.ruleNumber;i++){ PAddtion=localIFS.p[i]+PAddtion; } for(int i=0;i<localIFS.ruleNumber;i++){ localIFS.p[i]=localIFS.p[i]/PAddtion; } // size=Integer.parseInt(txtSize.getText());/* if (localcell.size<=0) return; localcell.per=Double.valueOf(txtPer.getText()).doubleValue(); if (localcell.per<=0||localcell.per>=1) return; localcell.refreshSteps=Integer.parseInt(txtRefreshSteps.getText()); if (localcell.refreshSteps<1) return;*/ localIFS.reinit(); localIFS.running=false; localIFS.btnStart.setLabel("开始"); this.hide(); this.dispose(); } return true; }else return false;}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -