⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abxresultspanel.java

📁 Java version of ABC/HR comparator v0.5. by schnofler. Runs on Sun JRE 1.5 or later
💻 JAVA
字号:
package abchr.gui;

import abchr.*;
import guiutils.LineLayout;

import javax.swing.*;
import java.awt.*;

public class ABXResultsPanel extends JPanel {
	private ABXTest test;

	private JTextField numTrialsField=new JTextField(3);
	private JTextField numCorrectField=new JTextField(3);
	private JTextField guessingField=new JTextField(5);
	private JTextArea progressArea=new JTextArea();

	private ABXTestFormatter formatter;

	public ABXResultsPanel() {
		super(new BorderLayout());

		numTrialsField.setEditable(false);
		numCorrectField.setEditable(false);
		guessingField.setEditable(false);
		numTrialsField.setHorizontalAlignment(JTextField.CENTER);
		numCorrectField.setHorizontalAlignment(JTextField.CENTER);
		guessingField.setHorizontalAlignment(JTextField.CENTER);
		progressArea.setEditable(false);

		JPanel topPanel=new JPanel(new LineLayout(LineLayout.CENTER,true));
		topPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
		topPanel.add(new JLabel("Correct"));
		topPanel.add(numCorrectField);
		topPanel.add(new JLabel("Total"));
		topPanel.add(numTrialsField);
		topPanel.add(LineLayout.lineBreak());
		topPanel.add(new JLabel("Prob. you were guessing"));
		topPanel.add(guessingField);
		this.add(topPanel,BorderLayout.NORTH);

		JScrollPane scrollPane=new JScrollPane(progressArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		scrollPane.setPreferredSize(new Dimension(180,150));
		this.add(scrollPane,BorderLayout.CENTER);
	}

	public ABXResultsPanel(ABXTestFormatter formatter) {
		this();
		this.formatter=formatter;
	}

	public ABXResultsPanel(boolean showSampleInfo) {
		this();
		SimpleABXTestFormatter formatter=new SimpleABXTestFormatter(null);
		formatter.setFormattingString(showSampleInfo?"Sample A: $A_SAMPLE$\nSample B: $B_SAMPLE$\n\n$RESULT_LIST$":"$RESULT_LIST$");
		formatter.setTrialFormattingString("$CORRECT$ of $TOTAL$, p $PVAL_EXT$");
		this.formatter=formatter;
	}

	public ABXTest getTest(){return test;}

	public void setTest(ABXTest test) {
		this.test=test;
		formatter.setTest(test);
		updateResults();
	}

	public void setListenableTest(ListenableABXTest test) {
		setTest(test);
		test.addListener(new ABXListener() {
			public void changed(ABXTest source){updateResults();}
		});
	}

	public void setFormatter(ABXTestFormatter formatter) {
		this.formatter=formatter;
	}

	public void updateResults() {
		if(test==null) {
			numTrialsField.setText("");
			numCorrectField.setText("");
			guessingField.setText("");
			guessingField.setBackground(UIManager.getColor("Label.background"));
			progressArea.setText("");
		} else {
			numTrialsField.setText(Integer.toString(test.getNumTrials()));
			numCorrectField.setText(Integer.toString(test.getCorrect()));
			float p=test.pVal();
			guessingField.setText(p<0.001?"<0.001":Float.toString(((int)(p*1000))/1000.0f));
			guessingField.setBackground(p<=0.01?Color.GREEN:(p<=0.05?Color.YELLOW:Color.RED));
			progressArea.setText(formatter.format());
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -