我正在我的高中学习计算机科学,我们正在用Java编程,对于我的最终项目,我正在为天文学制作一个自动数学计算器。我正在尝试使用方程列表创建一个下拉框,我已经编写了下拉框和动作侦听器以及常规GUI,我收到错误"类型mainScreen必须实现继承的抽象方法。我也遇到了很多其他错误,但这是主要错误。 java.awt.event.ActionListener.actionPerformed(java.awt.event.ActionEvent中)&#34 ;.抽象课我不是最好的。由于我还不熟悉Java编码,所以我不是最好的。这是我的代码:
import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;
public class mainScreen extends JFrame implements ActionListener
{
private static final String[] equations = {"Distance Mod", "Luminosity", "Mass of Binary"};
JComboBox equationList = new JComboBox(equations);
Jlabel whatEquation = new JLabel();
public static void main(String[] args)
{
mainScreen equat = new mainScreen();
centerFrame(equat);
equat.setVisable(true);
}
public mainScreen()
{
setLayout(new Flowlayout());
setSize(900, 800);
setTital("Astronomy Equations");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
equationList.setSelectedIndex(1);
equationList.addActionListener(this);
add(equationList);
add(whatEquation);
}
public void actionPreformed(ActionEvent e)
{
if(e.getSource() == equationList)
{
JcomboBox cb = (JComboBox)e.getSource());
String msg = (String)cb.getSelectedItems();
switch(msg)
{
case "Distance Mod" : whatEquation.setText("Please put in the known info and put a '0' if data is not known.");
break;
case "Luminosity" : whatEquation.setText("Please put in the known info and put a '0' if data is not known.");
break;
case "Mass of Binary" : whatEquation.setText("Please put in the known info and put a '0' if data is not known.");
break;
default : whatEquation.setText("Whoops. an error has occured please try again. :)");
}
}
}
}