import java.awt.*;
import javax.swing.*;
public class TypeIndicator {
//类常量
private final int WINDOW_WIDTH=400;
private final int WINDOW_HEIGHT=375;
private final int AREA_WIDTH=50;
private final String LEGEND="a series of priferences are asked.the responses are"+"" +
"used to setermine a personality type progile. the tool"+"is primitive and is meant for fun.you shoule not make"
+"any decisions based on its anslysis.";
//GUI实例变量
private JFrame window=new JFrame("Type Indicator"

;
//显示工具使用和局限性的文本信息
private JTextArea legendArea=new JTextArea(LEGEND,6,AREA_WIDTH);
//性格类型测试概要
private JTextArea resultArea=new JTextArea();
//当前喜好文本
private JTextArea statementPad=new JTextArea(LEGEND,1,AREA_WIDTH);
private JRadioButton trueButton=new JRadioButton("true "

;
private JRadioButton falseButton=new JRadioButton("false"

;
//隐藏的按钮肯定与不肯定的替换
private JRadioButton hiddenButton=new JRadioButton(" "

;
private ButtonGroup buttonGroup=new ButtonGroup();
//测试实例变量
private boolean introvert;
private boolean senser;
private boolean thinker;
private boolean judger;
//程序入口
public static void main(String args){
TypeIndicator testinstrument =new TypeIndicator ();
}//默认构造方法
public TypeIndicator ()
{ //设置GUI
configureAndDisplayGUI();
introvert=isIntroversionDominant();
senser=isSendingDominant();
thinker=isThinkingDominant();
judger=isJudgingDominant();
presentResults();
}
//设置GUI
private void configureAndDisplayGUI(){
//配置元素
window.setSize(WINDOW_WIDTH,WINDOW_HEIGHT);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
legendArea.setEnabled(false);
legendArea.setLineWrap(true);
legendArea.setWrapStyleWord(true);
legendArea.setBackground(window.getBackground());
statementPad.setVisible(false);
statementPad.setEditable(false);
statementPad.setBackground(window.getBackground());
trueButton.setVisible(false);
falseButton.setVisible(false);
buttonGroup.add(trueButton);
buttonGroup.add(falseButton);
buttonGroup.add(hiddenButton);
resultArea.setEditable(false);
resultArea.setBackground(window.getBackground());
//向窗口面板中增加元素
Container c=window.getContentPane();
c.setLayout(new FlowLayout());
c.add(legendArea);
c.add(statementPad);
c.add(trueButton);
c.add(falseButton);
c.add(resultArea);
//准备好GUI
window.setVisible(true);
}
//内向型比外向型主导
private boolean isIntroversionDominant(){
String s1="i prefer renting a video to going toparty";
String s2="i an happy when house guest leave";
String s3="meetnig new people makes me tense";
String s4="i enjoy being alone";
String s5="Crowds suck the life out of me";
return doTraitTest(s1,s2,s3,s4,s5);
}
private boolean isSendingDominant(){
String s1="facts are more intereste than ideas";
String s2=" i need the details more than the big pictrue";
String s3="i always measure,i never estimate";
String s4="seeing ts believing";
String s5="if you cannot touch it.it id not real ";
return doTraitTest(s1,s2,s3,s4,s5);
}
private boolean isThinkingDominant(){
String s1="i prefer page i to the comics in a newspaper";
String s2="i think therefore i am";
String s3="i am not an emotional person";
String s4="tears will not cause me to change my mind";
String s5="i rather be data than troi";
return doTraitTest(s1,s2,s3,s4,s5);
}
private boolean isJudgingDominant(){
String s1="it is easy to male a deision";
String s2="i an happy when house guest leave";
String s3="meetnig new people makes me tense";
String s4="i enjoy being alone";
String s5="Crowds suck the life out of me";
return doTraitTest(s1,s2,s3,s4,s5);}
//测试某个类型分类的主要反映
private boolean doTraitTest(String s1,String s2,String s3,String s4,String s5){
int choiceTrue=0;
int choiceFalse=0;
if(getTrueorFalseResponse(s1)){
++choiceTrue;
}else {++choiceFalse;}
if(getTrueorFalseResponse(s2)){
++choiceTrue;
}else {++choiceFalse;}
if(getTrueorFalseResponse(s3)){
++choiceTrue;
}else {++choiceFalse;}
if(getTrueorFalseResponse(s4)){
++choiceTrue;
}else {++choiceFalse;}
if(getTrueorFalseResponse(s5)){
++choiceTrue;
}else {++choiceFalse;}
//
return choiceTrue >choiceFalse;
}
private boolean getTrueorFalseResponse(String statement){
{statementPad.setText(statement);
hiddenButton.setSelected(true);
statementPad.setVisible(true);
trueButton.setVisible(true);
falseButton.setVisible(true);
for(;

{
if(trueButton.isSelected()||falseButton.isSelected()){
break;}
}
statementPad.setVisible(false);
trueButton.setVisible(false);
falseButton.setVisible(false);
return trueButton.isSelected();}
}
//显示
private void presentResults(){
String result ="your type is
"+" "+((introvert)? "i" : "e"

+((senser)? "s" : "n"

+((thinker)? "y" : "f"

+((judger)? "j" : "p"

+"
"+"where
"
+"*E=extroversion
"+"*I=introversion
"
+"*S=sensing
"+"*N=intuitive
"+"*T=thinking
"
+"*F=felling
"+"*J=judgment
"+"*P=perception
"
+"
"+"thank you for trying the tool";
resultArea.setText(result);
window.show();
}
}
为什么不能运行啊说是MAIN里没有TypeIndicator呢