import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Choice extends JDialog{
private JPanel panelMain;
private JButton btnPurchase;
private JButton btnRefund;
private JPanel cards;
final static String MainPage = "Main Page";
final static String PurchasePage = "Purchase Page";
final static String RefundPage = "Refund Page";
public Choice() {
setContentPane(panelMain);
setModal(true);
//getRootPane().setDefaultButton(buttonOK);
cards = new JPanel(new CardLayout());
cards.add(new Choice().ChoiceGUI(), MainPage);
cards.add(new Purchase().PurchaseGUI(), PurchasePage);
final CardLayout cl = (CardLayout) cards.getLayout();
cl.show(cards, MainPage);
btnPurchase.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cl.show(cards, PurchasePage);
}
});
btnRefund.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//refund click function
}
});
}
public JPanel ChoiceGUI (){
return panelMain;
}
public static void main(String[] args){
Choice dialog = new Choice();
dialog.pack();
dialog.setVisible(true);
System.exit(0);
}
}
That was Choice.java and below is Purchase.java
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Purchase extends Choice{
private JPanel panelPurchase;
private JLabel lblamnt;
private JButton btn1;
private JButton btn2;
private JButton btn3;
private JButton btn4;
private JButton btn5;
private JButton btn6;
private JButton btn7;
private JButton btn8;
private JButton btn9;
private JButton btn0;
private JButton btnClear;
private JButton btnSubmit;
/*
public Purchase(){
btn1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblamnt.setText(lblamnt.getText() + "1");
}
});
btn2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblamnt.setText(lblamnt.getText() + "2");
}
});
btn3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblamnt.setText(lblamnt.getText() + "3");
}
});
btn4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblamnt.setText(lblamnt.getText() + "4");
}
});
btn5.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblamnt.setText(lblamnt.getText() + "5");
}
});
btn6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblamnt.setText(lblamnt.getText() + "6");
}
});
btn7.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblamnt.setText(lblamnt.getText() + "7");
}
});
btn8.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblamnt.setText(lblamnt.getText() + "8");
}
});
btn9.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblamnt.setText(lblamnt.getText() + "9");
}
});
btn0.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblamnt.setText(lblamnt.getText() + "0");
}
});
btnClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblamnt.setText("");
}
});
btnSubmit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//run code to confirm and show next screen to display current currency exchange.
}
});
}
*/
public JPanel PurchaseGUI(){
return panelPurchase;
}
}
im getting tons of repeating errors. I am still learning how to use cardlayouts.
I get these errors when the program runs. it compiles fine.
Exception in thread "main" java.lang.StackOverflowError
at java.awt.Window.init(Window.java:507)
at java.awt.Window.<init>(Window.java:436)
at java.awt.Window.<init>(Window.java:591)
at java.awt.Dialog.<init>(Dialog.java:665)
at java.awt.Dialog.<init>(Dialog.java:409)
at javax.swing.JDialog.<init>(JDialog.java:272)
at javax.swing.JDialog.<init>(JDialog.java:206)
at javax.swing.JDialog.<init>(JDialog.java:154)
at src.Choice.<init>(Choice.java:18)
at src.Choice.<init>(Choice.java:23) (repeating)
Exception in thread "main" Exception in thread "main"
i redid purchase.java to include a GETTER
and the Choice.java errors are at
public Choice() {
and...
cards.add(new Choice().ChoiceGUI(), MainPage);
What am i doing wrong? I have been stuck here for the entire day without progress.
I am trying to have it set up so when i push the buy button it loads the purchase form within the same window.