Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
Verwende einfache FIFO Liste ... jeder Button der gedrückt wurde wird dort abgelegt in entsprechender Reihenfolge.
Sehe hier kein großes Problem.
package eu.sicusoft.demos;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.ListIterator;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class ButtonKlicks {
private static JButton btnLeft, btnRight, btnUp, btnDown;
private static LinkedList<String> listButton;
static int count = 0;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
listButton = new LinkedList<>();
btnRight = new JButton("RIGHT");
btnRight.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
++count;
getList(e.getActionCommand());
}
});
btnLeft = new JButton("LEFT");
btnLeft.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
++count;
getList(e.getActionCommand());
}
});
btnUp = new JButton("UP");
btnUp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
++count;
getList(e.getActionCommand());
}
});
btnDown = new JButton("DOWN");
btnDown.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
++count;
getList(e.getActionCommand());
}
});
JFrame f = new JFrame("ButtonKlickDemo");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(btnUp, BorderLayout.NORTH);
f.getContentPane().add(btnDown, BorderLayout.SOUTH);
f.getContentPane().add(btnLeft, BorderLayout.WEST);
f.getContentPane().add(btnRight, BorderLayout.EAST);
f.pack();
f.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
private static void getList(String in){
listButton.add(count+" - "+in);
System.out.println(listButton.getLast());
}
}