Я хочу добавить кнопки «назад» и «далее» для моего gui, но, похоже, это не работает. Такое ощущение, что я упускаю что-то важное в своем коде. Я пытался использовать cl.next(ImagePanel);
, но по какой-то причине метод не работает.
private void initComponents() {
mainPanel = new javax.swing.JPanel();
cardLayout = new java.awt.CardLayout();
imagePanel = new javax.swing.JPanel(cardLayout);
JLabel firstPicture = new JLabel("");
JLabel secondPicture = new JLabel("");
jButton back = new jButton("\u22b2Back");
jButton next = new jButton("Next\u22b3");
firstPicture.setIcon(...);
secondPicture.setIcon(...);
imagePanel.add(firstPicture, "1");
imagePanel.add(secondPicture, "2");
cardLayout.show(imagePanel, "1");
//...buttons actionPerformed(evt);
mainPanel.add(imagePanel);
}
private void backActionPerformed(java.awt.event.ActionEvent evt) {
CardLayout cl = (CardLayout) imagePanel.getLayout();
cl.previous(imagePanel); //should proceed to the previous image... not working
}
private void nextActionPerformed(java.awt.event.ActionEvent evt) {
CardLayout cl = (CardLayout) imagePanel.getLayout();
cl.next(imagePanel); //should proceed to the next image... not working
}