明確な答えを見つけることができませんでした。1つのボタンに複数のリスナーを含めることができることは知っていますが、その逆はどうでしょうか。現在、ButtonListenerに設定した2番目のボタンが応答しないという問題があり、それが理由かどうか疑問に思っています。私がやろうとしていたことが不可能な場合、別のButtonListenerをどのように設定しますか?
いつものように、どんな援助もありがたいです。
関連する情報源:
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.*;
import java.text.NumberFormat;
public class ClientApp extends JFrame
{
public static void main(String[] args)
{
new ClientApp();
}
//Declarations so they have scope outside of ClientApp()
private JButton switchCard;
private JPanel infoPanel;
private JPanel mainPanel;
private JPanel cartPanel;
private JPanel orderingPanel;
private JList candyList;
private CardLayout cl = new CardLayout();
private CardLayout cl2 = new CardLayout();
private JPanel checkoutPanel;
private JButton checkoutButton;
private JTextField acidPopsTF;
private JTextField bertieBottsTF;
private JTextField bloodPopsTF;
private JTextField cauldronCakesTF;
private JTextField charmChocTF;
private JTextField chocoballsTF;
private JTextField chocCauldronsTF;
private JTextField chocFrogsTF;
private JTextField chocWandsTF;
private JTextField roachClustersTF;
private JTextField crystalPineappleTF;
private JTextField droobleGumTF;
private JTextField explodeBonbonsTF;
private JTextField fizzWhizTF;
private JTextField iceMiceTF;
private JTextField jellySlugsTF;
private JTextField liquorWandsTF;
private JTextField pepImpsTF;
private JTextField pinkCocoIceTF;
private JTextField spindleSpidersTF;
private JTextField sugarQuillsTF;
private JTextField wizochocTF;
private JTextField shockChocTF;
private ArrayList cart;
private Object[] cartArray;
public ClientApp()
{
this.setSize(750,400);
this.setTitle("Honeydukes Muggle Ordering System");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ButtonListener bl = new ButtonListener();
//Creating the panels
mainPanel = new JPanel(cl2);
cartPanel = new JPanel();
orderingPanel = new JPanel(new BorderLayout());
infoPanel = new JPanel(cl);
JPanel invntryPanel = new JPanel(new BorderLayout());
checkoutPanel = new JPanel(new BorderLayout());
//-----コードコードコード----//
//Creating the interface element for advancing to the checkout screen
checkoutButton = new JButton("Checkout");
checkoutButton.addActionListener(bl);
checkoutPanel.add(checkoutButton, BorderLayout.LINE_END);
//Adding everything to the frame
orderingPanel.add(checkoutPanel, BorderLayout.PAGE_END);
orderingPanel.add(invntryPanel, BorderLayout.LINE_START);
orderingPanel.add(infoPanel, BorderLayout.CENTER);
mainPanel.add(orderingPanel, "Ordering");
mainPanel.add(cartPanel, "Cart");
if (currentPage == 1)
{
cl2.show(mainPanel, "Cart");
}
if (currentPage == 0)
{
cl2.show(mainPanel, "Ordering");
}
this.add(mainPanel);
this.setVisible(true);