新人求助一直提示找不到符号

时间:2021-10-01 17:46:45
public class kht3_1{
   public static void main(String args[]){
      MyFrame myFrame = new MyFrame();
      myFrame.setBounds(100,100,590,500);
      myFrame.setTitle("计算");
   }
}
=================上面是主类==========================
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.util.*;
public class MyFrame extends Frame implements DocumentListener{
   JTextArea inputText,showText;
   MyFrame(){
      init();
      setLayout(new FlowLayout());
      setVisible(true);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//编译一直显示:找不到符号
                                                                                              //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                                                                             //   ^
                                                                                             // 符号:   方法 setDefaultCloseOperation(int)
                                                                                            //位置: 类 MyFrame
                                                                                                //1 个错误
   }
   void init(){
      JPanel jpanel=new JPanel();
      inputText = new JTextArea(15,20);
      showText = new JTextArea(15,20);
      showText.setLineWrap(true);
      inputText.setLineWrap(true);
      (inputText.getDocument()).addDocumentListener(this);
      inputText.requestFocusInWindow();
      add(new JScrollPane(inputText));
      add(new JScrollPane(showText));
   }
   public void changedUpdate(DocumentEvent e){
      StringTokenizer fenxi =new StringTokenizer(inputText.getText()," ,");
      double sum= 0,aver=0;
      int count = fenxi.countTokens();
      while(fenxi.hasMoreTokens()){
         double item = Double.parseDouble(fenxi.nextToken());
         sum=sum+item;
      }
      aver=sum/count;
      showText.setText(null);
      showText.append("和是"+sum+"  平均值是"+aver);
   }
   public void removeUpdate(DocumentEvent e){
      changedUpdate(e);
   }
   public void insertUpdate(DocumentEvent e){
      changedUpdate(e);
   }
}
================================================

编译显示的错误:\MyFrame.java:12: 错误: 找不到符号
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      ^
  符号:   方法 setDefaultCloseOperation(int)
  位置: 类 MyFrame
1 个错误

2 个解决方案

#1


将继承Frame
改成继承JFrame

#2


 setDefaultCloseOperation为JFrame中方法,JFrame需要初始化一个对象

#1


将继承Frame
改成继承JFrame

#2


 setDefaultCloseOperation为JFrame中方法,JFrame需要初始化一个对象