📄 animaltest.java
字号:
import java.awt.BorderLayout;
import java.awt.Color;
//import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.*;
public class animalTest extends JApplet
{
/**
*
*/
private static final long serialVersionUID = -83512185731024242L;
private JTextArea input;
private JTextArea depict;
private JButton certain;
private boolean modeOdd=true;
private JPanel panel;
private JLabel displayName,displayLabel;
public void init()
{
input = new JTextArea();
input.setBounds(50, 120, 200, 250);
input.setBackground(new Color(155, 250, 120));
input.setLineWrap(true);
depict = new JTextArea();
depict.setBounds(300, 120, 200, 250);
depict.setBackground(new Color(155, 250, 120));
depict.setLineWrap(true);
displayName = new JLabel("请输入条件:");
displayName.setBounds(50, 0, 200, 150);
displayLabel = new JLabel("推理显示");
displayLabel.setBounds(300, 0, 150, 150);
certain = new JButton("确定");
certain.setBounds(100, 420, 80, 40);
JScrollPane pane = new JScrollPane(depict);
pane.setBounds(300, 120, 200, 250);
panel = new JPanel();
panel.setLayout(null);
panel.add(input);
panel.add(certain);
panel.add(displayName);
panel.add(displayLabel);
panel.add(pane);
getContentPane().add(panel, BorderLayout.CENTER);
certain.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(e.getSource()==certain)
{
ArrayList<String> userDemandList = new ArrayList<String>();
String str = input.getText();
Scanner s = new Scanner(str);
while (s.hasNext()) {
userDemandList.add(s.next());
}
SearchAnimal searchAnimal = new SearchAnimal(userDemandList);
String animalName = searchAnimal.search(modeOdd);
if (animalName != null) {
animalTest.this.depict.setText(animalName + "\n");
animalTest.this.depict.append("推理过程如下:"+"\n");
List<ArrayList> infCause = searchAnimal.getInfCause();
List<String> infResult = searchAnimal.getInfResult();
int i=0;
for (ArrayList<String> causeList:infCause) {
for (String cause : causeList)
animalTest.this.depict.append(cause + "\n");
animalTest.this.depict.append("推出:");
animalTest.this.depict.append(infResult.get(i) + "\n");
i++;
}
} else {
JOptionPane.showInputDialog(animalTest.this);
}
}
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -