package Kinematics;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
public class Display extends JFrame implements Runnable{
private static final long serialVersionUID = 938633141149262027L;
static JButton b2 = new JButton("v/t");
static JButton b1 = new JButton("d/t");
static JFrame frame = new JFrame("Kinematics Conversions");
static JFrame frame2 = new JFrame("Kinematics Conversions");
public static void main(String[] args){
frame.setVisible(true);
JPanel p = new JPanel();
frame.setPreferredSize(new Dimension(500, 500));
b1.setBounds(5, 5, 5, 5);
b1.addActionListener(ActionListener -> {
public void actionPerformed(ActionEvent e){ //says actionPerformed cannot have void return type
if(b2.getModel().isPressed()) { //however the oracle site says otherwise
frame.setVisible(false);
frame2.setVisible(true);
}
}
});
b2.setBounds(50, 50, 5, 5);
p.add(b1);
p.add(b2);
frame.add(p);
frame.pack();
}
@Override
public void run() {
if(b2.getModel().isPressed()) {
frame.setVisible(false);
frame2.setVisible(true);
}
}
}
好的,所以我的语法正确..我想。我进入了oracle网站查看语法和正确的返回类型,但ECLIPSE OXYGEN 2.0说actionPerformed不能返回类型为void。那是为什么?