access methods from a private
In the GUI event handlers I need to access these methods...you can see them, they are commented out. The problem is that Menu(); is private.Can someone give me some help here on how to call these methods?
/*
* MenuGui.java
*
* Created on June 9, 2007, 11:34 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author pberardi
*/
/** Creates a new instance of MenuGui */
/*
* CustomerClassGUI.java
*
* Created on June 5, 2007, 1:22 PM
*/
/**
*
* @author pberardi
*/
publicclass MenuGuiextends javax.swing.JDialog{
int total1;
/** Creates new form CustomerClassGUI */
public MenuGui(java.awt.Frame parent,boolean modal){
super(parent, modal);
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
privatevoid initComponents(){
largeCoffee =new javax.swing.JButton();
smallCoffee =new javax.swing.JButton();
depositFiveCents =new javax.swing.JButton();
depositTenCents =new javax.swing.JButton();
depositTwentyFiveCents =new javax.swing.JButton();
sugar =new javax.swing.JButton();
extraSugar =new javax.swing.JButton();
creamer =new javax.swing.JButton();
extraCreamer =new javax.swing.JButton();
submit =new javax.swing.JButton();
buttonSelected =new javax.swing.JLabel();
totalDeposited =new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
largeCoffee.setText("Large Coffee");
largeCoffee.addActionListener(new java.awt.event.ActionListener(){
publicvoid actionPerformed(java.awt.event.ActionEvent evt){
largeCoffeeActionPerformed(evt);
}
});
smallCoffee.setText("Small Coffee");
smallCoffee.addActionListener(new java.awt.event.ActionListener(){
publicvoid actionPerformed(java.awt.event.ActionEvent evt){
smallCoffeeActionPerformed(evt);
}
});
depositFiveCents.setText("Deposit 5 Cents");
depositFiveCents.addActionListener(new java.awt.event.ActionListener(){
publicvoid actionPerformed(java.awt.event.ActionEvent evt){
depositFiveCentsActionPerformed(evt);
}
});
depositTenCents.setText("Deposit 10 Cents");
depositTenCents.addActionListener(new java.awt.event.ActionListener(){
publicvoid actionPerformed(java.awt.event.ActionEvent evt){
depositTenCentsActionPerformed(evt);
}
});
depositTwentyFiveCents.setText("Deposit 25 Cents");
depositTwentyFiveCents.addActionListener(new java.awt.event.ActionListener(){
publicvoid actionPerformed(java.awt.event.ActionEvent evt){
depositTwentyFiveCentsActionPerformed(evt);
}
});
sugar.setText("Sugar");
sugar.addActionListener(new java.awt.event.ActionListener(){
publicvoid actionPerformed(java.awt.event.ActionEvent evt){
sugarActionPerformed(evt);
}
});
extraSugar.setText("Extra Sugar");
extraSugar.addActionListener(new java.awt.event.ActionListener(){
publicvoid actionPerformed(java.awt.event.ActionEvent evt){
extraSugarActionPerformed(evt);
}
});
creamer.setText("Creamer");
creamer.addActionListener(new java.awt.event.ActionListener(){
publicvoid actionPerformed(java.awt.event.ActionEvent evt){
creamerActionPerformed(evt);
}
});
extraCreamer.setText("Extra Creamer");
extraCreamer.addActionListener(new java.awt.event.ActionListener(){
publicvoid actionPerformed(java.awt.event.ActionEvent evt){
extraCreamerActionPerformed(evt);
}
});
submit.setText("Submit");
submit.addActionListener(new java.awt.event.ActionListener(){
publicvoid actionPerformed(java.awt.event.ActionEvent evt){
submitActionPerformed(evt);
}
});
buttonSelected.setText(" ");
javax.swing.GroupLayout layout =new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(largeCoffee, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(smallCoffee, javax.swing.GroupLayout.Alignment.LEADING))
.addGap(127, 127, 127)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,false)
.addComponent(depositFiveCents, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(depositTenCents, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(depositTwentyFiveCents))
.addGap(93, 93, 93)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(extraCreamer, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
.addComponent(creamer, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
.addComponent(sugar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
.addComponent(extraSugar, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE))
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(44, 44, 44)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(totalDeposited)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 417, Short.MAX_VALUE)
.addComponent(submit)
.addGap(53, 53, 53))
.addGroup(layout.createSequentialGroup()
.addComponent(buttonSelected)
.addContainerGap(532, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(largeCoffee)
.addComponent(sugar)
.addComponent(depositFiveCents))
.addGap(15, 15, 15)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(smallCoffee)
.addComponent(depositTenCents)
.addComponent(extraSugar))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(14, 14, 14)
.addComponent(creamer)
.addGap(14, 14, 14)
.addComponent(extraCreamer)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 91, Short.MAX_VALUE)
.addComponent(submit)
.addGap(20, 20, 20))
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(depositTwentyFiveCents)
.addGap(60, 60, 60)
.addComponent(buttonSelected)
.addGap(36, 36, 36)
.addComponent(totalDeposited)
.addGap(51, 51, 51))))
);
pack();
}// </editor-fold>
privatevoid submitActionPerformed(java.awt.event.ActionEvent evt){
// TODO add your handling code here:
buttonSelected.setText("You just clicked the submit button");
// done =true;
// selectDone();
Payment p =new Payment();
p.computePayment(ScenarioSteps.SEL_LARGE_COFFEE);
CoinBank cb = CoinBank.getInstance();
cb.insertCoin(100,p);
//clearOrder();
}
privatevoid extraCreamerActionPerformed(java.awt.event.ActionEvent evt){
// TODO add your handling code here:
buttonSelected.setText("You just clicked the select extra creamer button");
//selectextraCreamer();
}
privatevoid creamerActionPerformed(java.awt.event.ActionEvent evt){
// TODO add your handling code here:
buttonSelected.setText("You just clicked the select creamer button");
// selectCreamer();
}
privatevoid extraSugarActionPerformed(java.awt.event.ActionEvent evt){
// TODO add your handling code here:
buttonSelected.setText("You just clicked the select extra sugar button");
//selectExtraSugar();
}
privatevoid sugarActionPerformed(java.awt.event.ActionEvent evt){
// TODO add your handling code here:
buttonSelected.setText("You just clicked the select sugar button");
//selectSugar();
}
privatevoid depositTwentyFiveCentsActionPerformed(java.awt.event.ActionEvent evt){
// TODO add your handling code here:
total1 = total1 + 25;
totalDeposited.setText ("total deposited is " + total1 +" cents");
buttonSelected.setText("You just clicked the twenty-five cent button");
}
privatevoid depositTenCentsActionPerformed(java.awt.event.ActionEvent evt){
// TODO add your handling code here:
total1 = total1 + 10;
totalDeposited.setText ("total deposited is " + total1 +" cents");
buttonSelected.setText("You just clicked the ten cent button");
}
privatevoid depositFiveCentsActionPerformed(java.awt.event.ActionEvent evt){
// TODO add your handling code here:
total1 = total1 + 5;
totalDeposited.setText ("total deposited is " + total1 +" cents");
buttonSelected.setText("You just clicked the five cent button");
}
privatevoid smallCoffeeActionPerformed(java.awt.event.ActionEvent evt){
// TODO add your handling code here:
buttonSelected.setText("You just clicked the select small coffee button");
//smallCoffee();
}
privatevoid largeCoffeeActionPerformed(java.awt.event.ActionEvent evt){
// TODO add your handling code here:
buttonSelected.setText("You just clicked the select large coffee button");
//selectLargeCoffee();
}
/**
* @param args the command line arguments
*/
publicstaticvoid main(String args[]){
java.awt.EventQueue.invokeLater(new Runnable(){
publicvoid run(){
new MenuGui(new javax.swing.JFrame(),true).setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel buttonSelected;
private javax.swing.JButton creamer;
private javax.swing.JButton depositFiveCents;
private javax.swing.JButton depositTenCents;
private javax.swing.JButton depositTwentyFiveCents;
private javax.swing.JButton extraCreamer;
private javax.swing.JButton extraSugar;
private javax.swing.JButton largeCoffee;
private javax.swing.JButton smallCoffee;
private javax.swing.JButton submit;
private javax.swing.JButton sugar;
private javax.swing.JLabel totalDeposited;
// End of variables declaration
}
import java.util.Scanner;
publicclass Menu{
privateint MAX_SELECTIONS=10;
privateint[] order =newint[MAX_SELECTIONS];
privateint orderEnd=0;
//remember to clear these in the clearOrder method
privateboolean largeCoffeeSelected=false;
privateboolean creamerSelected=false;
privateboolean sugarSelected=false;
privateboolean extraCreamerSelected=false;
privateboolean extraSugarSelected=false;
privatestatic Menu instance=null;
publicboolean done =false;
publicstatic Menu getInstance(){//call this instead of constructor
if(instance ==null)
instance =new Menu();
return instance;
}
private Menu(){
}
publicvoid performInteractiveMenu(){// you have to fix and finish this code off
// boolean done = false;
clearOrder();
Scanner inputScanner =new Scanner(System.in);
while( done ==false ){
System.out.println("For SEL_LARGE_COFFEE Enter 1");
System.out.println("For SEL_SUGAR Enter 2");
System.out.println("For SEL_XSUGAR Enter 3");
System.out.println("For SEL_CREAMER Enter 4");
System.out.println("For SEL_XCREAMER Enter 5" );
System.out.println("For SEL_DONE Enter -1" );
Scanner input =new Scanner(System.in);
int choice =0;
choice = inputScanner.nextInt();
//Read in this number choice
//read in the number that is entered, (Similar to discussion board exercise);
switch(choice){
case ScenarioSteps.SEL_LARGE_COFFEE:
selectLargeCoffee();
break;
// finish off the switch statement
case ScenarioSteps.SEL_CREAMER:
selectCreamer();
break;
//Finish off
case ScenarioSteps.SEL_SUGAR:
selectSugar();
break;
case ScenarioSteps.SEL_XSUGAR:
selectExtraSugar();
break;
case ScenarioSteps.SEL_XCREAMER:
selectCreamer();
break;
case ScenarioSteps.SEL_DONE:
done =true;
selectDone();
Payment p =new Payment();
p.computePayment(ScenarioSteps.SEL_LARGE_COFFEE);
CoinBank cb = CoinBank.getInstance();
cb.insertCoin(100,p);
clearOrder();
break;
};
}//end while
}
//Student's are to add this method as part of Phase 2 IP
publicvoid clearOrder(){
for(int i=0; i < MAX_SELECTIONS; i++)
order[i]=0;
largeCoffeeSelected=false;
creamerSelected=false;
sugarSelected=false;
extraCreamerSelected=false;
extraSugarSelected=false;
}
publicvoid selectLargeCoffee(){
System.out.println("Menu.selectLargeCoffee: Selecting Large Coffee");
if(largeCoffeeSelected==false){//incase the user selects>1X
largeCoffeeSelected=true;
if(orderEnd<MAX_SELECTIONS)
order[orderEnd++]=ScenarioSteps.SEL_LARGE_COFFEE;
else
System.out.println("Maximum selections exceeded. Abort order!");
}//if
}//selectLargeCoffee
publicvoid selectCreamer(){
System.out.println("Menu.selectCreamer: Selecting Creamer");
if(creamerSelected==false){//incase the user selects>1X
creamerSelected=true;
if(orderEnd<MAX_SELECTIONS)
order[orderEnd++]=ScenarioSteps.SEL_CREAMER;
else
System.out.println("Maximum selections exceeded. Abort order!");
}//if//copy paste and change the code for selectLargeCoffee here for creamer
}
publicvoid selectSugar(){
System.out.println("Menu.selectSugar: Selecting Sugar");
if(sugarSelected==false){//incase the user selects>1X
sugarSelected=true;
if(orderEnd<MAX_SELECTIONS)
order[orderEnd++]=ScenarioSteps.SEL_SUGAR;
else
System.out.println("Maximum selections exceeded. Abort order!");
}//if //copy paste and change the code for selectLargeCoffee here for sugar
}
publicvoid selectExtraSugar(){
System.out.println("Menu.selectextraSugar: Selecting Extra Sugar");
if(extraSugarSelected==false){//incase the user selects>1X
extraSugarSelected=true;
if(orderEnd<MAX_SELECTIONS)
order[orderEnd++]=ScenarioSteps.SEL_XSUGAR;
else
System.out.println("Maximum selections exceeded. Abort order!");
}//if//copy paste and change the code for selectLargeCoffee here for extra-sugar
}
publicvoid selectDone(){
System.out.println("Done making selections.\nCompute Payment and Change");
done =true;
Payment p =new Payment();
p.computePayment(ScenarioSteps.SEL_LARGE_COFFEE);
}
publicvoid setPaidInfull(){
}
publicint[] getIngredients()
{
System.out.println("Now calling .getIngredients");
return order;
}
publicint getMAX_SELECTIONS(){
return MAX_SELECTIONS;
}
publicvoid setMAX_SELECTIONS(int val){
this.MAX_SELECTIONS = val;
}
publicint[] getOrder(){
return order;
}
publicvoid setOrder(int[] val){
this.order = val;
}
publicint getOrderEnd(){
return orderEnd;
}
publicvoid setOrderEnd(int val){
this.orderEnd = val;
}
publicboolean getLargeCoffeeSelected(){
return largeCoffeeSelected;
}
publicvoid setLargeCoffeeSelected(boolean val){
this.largeCoffeeSelected = val;
}
publicvoid setInstance(Menu val){
this.instance = val;
}
}
>

