Question
public class Final extends JFrame { private double total ; private double total2; private double total3; private final int sides = 3; private int value;
public class Final extends JFrame { private double total ; private double total2; private double total3;
private final int sides = 3; private int value; private int value2; private int value3; private JPanel panel; private JLabel Win; private JLabel endLabel; private JLabel AmountLabel; private JLabel totalAmount; private JLabel imageLabel1; private JLabel imageLabel2; private JLabel imageLabel3; private JTextField EnteredMoney; private JTextField endMoney; private JTextField totalMoney; private JButton Amount; private final int WINDOW_WIDTH = 5000; private final int WINDOW_HEIGHT = 300; private Window1 window;
public Final() { setTitle("Dice Simulator");
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildPanel();
setVisible(true); }
public void buildPanel() { AmountLabel = new JLabel("Amount Inserted: $");
EnteredMoney = new JTextField(10);
endLabel = new JLabel("You have won: $");
endMoney = new JTextField(10);
endMoney.setEditable(false);
totalAmount = new JLabel("Total amount won is");
totalMoney = new JTextField(10);
totalMoney.setEditable(false);
imageLabel1 = new JLabel();
imageLabel2 = new JLabel();
imageLabel3 = new JLabel();
Amount = new JButton("Spin");
Amount.addActionListener(new AmountListener());
JPanel panel = new JPanel(); JPanel panel2 = new JPanel(); JPanel panel3 = new JPanel(); JPanel panel4 = new JPanel();
panel = new JPanel(); panel2 = new JPanel(); panel3 = new JPanel(); panel4 = new JPanel();
panel.add(AmountLabel); panel.add(EnteredMoney); panel.add(endLabel); panel.add(endMoney); panel.add(totalAmount); panel.add(totalMoney); panel2.add(imageLabel1); panel2.add(imageLabel2); panel4.add(imageLabel3); panel3.add(Amount);
add(panel,BorderLayout.WEST); add(panel2,BorderLayout.NORTH); add(panel3,BorderLayout.SOUTH); add(panel4,BorderLayout.EAST);
}
private class AmountListener implements ActionListener { public void actionPerformed(ActionEvent e) {
NatoliSlot Roll = new NatoliSlot();
value = Roll.getValue(); value2 = Roll.getValue2(); value3 = Roll.getValue3();
String Emoney =""; double eMoney = 0.0;
double Doubel =0.0;
Emoney = EnteredMoney.getText();
eMoney = Double.parseDouble(Emoney);
switch(value) { case 1 : ImageIcon set = new ImageIcon("cherry.jpg"); imageLabel1.setIcon(set); break;
case 2: ImageIcon set2 = new ImageIcon("lemon.png"); imageLabel1.setIcon(set2); break;
case 3: ImageIcon set3 = new ImageIcon("watermelon.jpg"); imageLabel1.setIcon(set3); break;
}//end of vlaue switch
switch(value2) { case 1 : ImageIcon set = new ImageIcon("cherry.jpg"); imageLabel2.setIcon(set); break;
case 2: ImageIcon set2 = new ImageIcon("lemon.png"); imageLabel2.setIcon(set2); break;
case 3: ImageIcon set3 = new ImageIcon("watermelon.jpg"); imageLabel2.setIcon(set3); break;
}// end of value2 switch
switch(value3) { case 1 : ImageIcon set = new ImageIcon("cherry.jpg"); imageLabel3.setIcon(set); break;
case 2: ImageIcon set2 = new ImageIcon("lemon.png"); imageLabel3.setIcon(set2); break;
case 3: ImageIcon set3 = new ImageIcon("watermelon.jpg"); imageLabel3.setIcon(set3); break; }// end of value3 switch
DoubleScore D = new DoubleScore(); total3 = D.setNum(eMoney,value,value2,value3); endMoney.setText(String.format("%f",(total3))); total+=total3; totalMoney.setText(String.format("%f",(total)));
if(total3 >0) { window = new Window1(); window.setVisible(true);
}
}
} public static void main(String [] args) { new Final(); }
}
public class Window1 extends JFrame { private JPanel panel; private JButton Exit; private JButton Again; private JLabel Win;
private final int WINDOW_WIDTH = 500; private final int WINDOW_HEIGHT = 300;
public Window1() { setSize(WINDOW_WIDTH, WINDOW_HEIGHT); setLayout(new BorderLayout()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); buildPanel1(); playSound(); setVisible(false);
}
public void buildPanel1() {
Exit = new JButton("Cash Out"); Exit.addActionListener(new ExitListener()); Again = new JButton("Spin Again"); Again.addActionListener(new AgainListener()); ImageIcon set = new ImageIcon("Jackpot.jpg"); Win.setIcon(set);
JPanel panel = new JPanel(); JPanel panel2 = new JPanel(); JPanel panel3 = new JPanel(); panel = new JPanel(); panel2 = new JPanel(); panel3 = new JPanel();
panel.add(Again); panel2.add(Exit); panel2.add(Win);
add(panel,BorderLayout.NORTH); add(panel2,BorderLayout.SOUTH);
}
public void playSound() {
try { AudioInputStream audioIn = AudioSystem.getAudioInputStream(Window1.class.getResource("Coins_sound_effect.wav")); Clip clip = AudioSystem.getClip(); clip.open(audioIn); clip.start(); }
catch(Exception e) { System.out.println("The sound file does not exist!!!"); } }
private class ExitListener implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0);
} }
private class AgainListener implements ActionListener { public void actionPerformed(ActionEvent e) { setVisible(false);
}
}
}
I dont know why this error, Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException is happening? I had the prgram working befor but I dont know what happend.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started