import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
import javax.swing.JOptionPane;
public class teacherchioce3 extends JFrame implements ActionListener,ItemListener
{
JFrame f=new JFrame();
JLabel lab1;
JTextField  text1;
JTextArea ta1;
JButton but;
Choice cho,cho1;
String str1,str2,str[]={"王芳","刘英杰","张琳","王靖宇","黄希","蒙娜","辛婷玉","谭佳思",
"昭阳","李荣","杜晓峰","施威","雨晨","陆美贺","蒋冠明"};
public static void main(String args[])
{
new teacherchioce3();
   
}
 
teacherchioce3()
{
super("判断是否为优秀!");

addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
f.setSize(400,500);
f.setLocation(200,200);
f.setBackground(Color.darkGray);
f.setResizable(true);
f.setVisible(true);
f.setFont(new Font("Arial",Font.PLAIN,14));
//-------
    cho=new Choice();
cho.add("教师");
cho.add("学生");
    cho.setBounds(60,100,80,30);
    f.getContentPane().add(cho);
cho.addItemListener(this);
//------
cho1=new Choice();
for(int i=0;i<str.length;i++)
{
    cho1.add(str[i]);
}
cho1.setBounds(180,100,80,30);
f.getContentPane().add(cho1);
    cho1.addItemListener(this);
    //-------
ta1=new JTextArea(200,100);
    ta1.setBounds(60,150,200,100);
f.getContentPane().add(ta1);
//------
lab1=new JLabel("您的分数:");
lab1.setBounds(60,270,60,30);
f.getContentPane().add(lab1);
//------
text1=new JTextField();
text1.setBounds(180,270,80,30);
f.getContentPane().add(text1);
text1.addActionListener(this);
//----
but=new JButton("提交");
but.addActionListener(this);
but.setBounds(210,330,50,30);
f.getContentPane().add(but);
f.show();
}
public void actionPerformed(ActionEvent e)
{

   /* if(e.getSource()==but)
   {
    
    if(str1=="教师"){
   if(Integer.parseInt(text1.getText())>3)
ta1.append("教师"+str2+"是优秀教师!"+"\n"); 
else
ta1.append("教师"+str2+"不是优秀教师!"+"\n"); 
   }
   
   if(str1=="学生"){
    if(Integer.parseInt(text1.getText())>90)
ta1.append("学生"+str2+"是优秀学生!"+"\n"); 
else
ta1.append("学生"+str2+"不是优秀学生!"+"\n"); 
   
   }
}*/
//------
if(e.getSource()==but)
   {
    
    if(str1=="教师"){
   if(Integer.parseInt(text1.getText())>3)
ta1.setText("教师"+str2+"是优秀教师!"+"\n"); 
else
ta1.setText("教师"+str2+"不是优秀教师!"+"\n"); 
   }
   
   if(str1=="学生"){
    if(Integer.parseInt(text1.getText())>90)
ta1.setText("学生"+str2+"是优秀学生!"+"\n"); 
else
ta1.setText("学生"+str2+"不是优秀学生!"+"\n"); 
   
   }
}
}
public void itemStateChanged(ItemEvent e)
{
    
     str1=(String)cho.getSelectedItem();
     str2=(String)cho1.getSelectedItem();

}
}

解决方案 »

  1.   

    import java.awt.*;public class teacherchioce3 extends JFrame implements ActionListener,
    ItemListener {
    JFrame f = new JFrame();
    JLabel lab1;
    JTextField text1;
    JTextArea ta1;
    JButton but;
    Choice cho, cho1;
    String str1, str2, str[] = { "王芳", "刘英杰", "张琳", "王靖宇", "黄希", "蒙娜", "辛婷玉",
    "谭佳思", "昭阳", "李荣", "杜晓峰", "施威", "雨晨", "陆美贺", "蒋冠明" }; public static void main(String args[]) {
    new teacherchioce3(); } teacherchioce3() {
    super("判断是否为优秀!"); f.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    }
    });
    f.setSize(400, 500);
    f.setLocation(200, 200);
    f.setBackground(Color.darkGray);
    f.setResizable(true);
    f.setFont(new Font("Arial", Font.PLAIN, 14));
    f.getContentPane().setLayout(null);
    // -------
    cho = new Choice();
    cho.add("教师");
    cho.add("学生");
    cho.setBounds(60, 100, 80, 30);
    f.getContentPane().add(cho);
    cho.addItemListener(this);
    // ------
    cho1 = new Choice();
    for (int i = 0; i < str.length; i++) {
    cho1.add(str[i]);
    }
    cho1.setBounds(180, 100, 80, 30);
    f.getContentPane().add(cho1);
    cho1.addItemListener(this);
    // -------
    ta1 = new JTextArea(200, 100);
    ta1.setBounds(60, 150, 200, 100);
    f.getContentPane().add(ta1);
    // ------
    lab1 = new JLabel("您的分数:");
    lab1.setBounds(60, 270, 60, 30);
    f.getContentPane().add(lab1);
    // ------
    text1 = new JTextField();
    text1.setBounds(180, 270, 80, 30);
    f.getContentPane().add(text1);
    text1.addActionListener(this);
    // ----
    but = new JButton("提交");
    but.addActionListener(this);
    but.setBounds(210, 330, 50, 30);
    f.getContentPane().add(but); f.setVisible(true);
    } public void actionPerformed(ActionEvent e) { /*
     * if(e.getSource()==but) {
     * 
     * if(str1=="教师"){ if(Integer.parseInt(text1.getText())>3)
     * ta1.append("教师"+str2+"是优秀教师!"+"\n"); else
     * ta1.append("教师"+str2+"不是优秀教师!"+"\n"); }
     * 
     * if(str1=="学生"){ if(Integer.parseInt(text1.getText())>90)
     * ta1.append("学生"+str2+"是优秀学生!"+"\n"); else
     * ta1.append("学生"+str2+"不是优秀学生!"+"\n");
     * 
     * } }
     */
    // ------
    if (e.getSource() == but) { if (str1 == "教师") {
    if (Integer.parseInt(text1.getText()) > 3)
    ta1.setText("教师" + str2 + "是优秀教师!" + "\n");
    else
    ta1.setText("教师" + str2 + "不是优秀教师!" + "\n");
    } if (str1 == "学生") {
    if (Integer.parseInt(text1.getText()) > 90)
    ta1.setText("学生" + str2 + "是优秀学生!" + "\n");
    else
    ta1.setText("学生" + str2 + "不是优秀学生!" + "\n"); }
    }
    } public void itemStateChanged(ItemEvent e) { str1 = (String) cho.getSelectedItem();
    str2 = (String) cho1.getSelectedItem(); }
    }做了最基础的修改,可以正常显示和退出了
    问题还有很多,慢慢去改吧