Что мне кажется: у вас есть
JMenuBar menuBar = new JMenuBar();
JMenu file = new JMenu("File");
JMenuItem exitItem = new JMenuItem("Exit");
exitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
System.exit(0);
}
});
JMenu headMenu = new JMenu("Heads");
вне определения какого-либо метода, и нет способа вызвать этот код.
Попробуйте следующее:
public class Main extends JFrame{
//initialize integer height/width values along with declaring
//Swing component variables
private final int W = 500,
H = 500;
private JMenu file, headMenu, bgMenu;
private JMenuBar menuBar;
private JMenuItem exitItem;
//constructor
public Main(){
setTitle("Move the Head");
setSize(W, H);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
initializeElements();
}
//Initializes the elements, this part is missing from your code above.
public void initializeElements(){
menuBar = new JMenuBar();
file = new JMenu("File");
exitItem = new JMenuItem("Exit");
exitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
System.exit(0);
}
});
headMenu = new JMenu("Heads");
bgMenu = new JMenu("Backgrounds");
}
public static void main( String[] args ) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Main f = new Main();
f.setVisible(true);
}
});
}
}
Может использовать np.roll
для нахождения последнего индекса трех последовательных значений.
import numpy as np
idx = ((l == np.roll(l, 1)) & (l == np.roll(l, 2))).cumsum().argmax()
l[idx:]
#[1, 2, 4, 1, 3, 5, 2, 2, 6, 4, 1, 6, 1, 1, 3, 5, 2, 2, 6, 4, 1, 6, 2, 7, 2, 6, 1, 1]