0 Members and 1 Guest are viewing this topic.
JLabel win = new JLabel("YOU WIN!"); win.setFont(new Font("Serif", Font.BOLD, 42)); win.setForeground(Color.red);
--------------------Configuration: <Default>--------------------E:\adv. comp sci\slot machine\slotmachine.java:21: <identifier> expected win.setFont(new Font("Serif", Font.BOLD, 42)); ^E:\adv. comp sci\slot machine\slotmachine.java:21: illegal start of type win.setFont(new Font("Serif", Font.BOLD, 42)); ^E:\adv. comp sci\slot machine\slotmachine.java:21: ')' expected win.setFont(new Font("Serif", Font.BOLD, 42)); ^E:\adv. comp sci\slot machine\slotmachine.java:21: ';' expected win.setFont(new Font("Serif", Font.BOLD, 42)); ^E:\adv. comp sci\slot machine\slotmachine.java:21: illegal start of type win.setFont(new Font("Serif", Font.BOLD, 42)); ^E:\adv. comp sci\slot machine\slotmachine.java:21: <identifier> expected win.setFont(new Font("Serif", Font.BOLD, 42)); ^E:\adv. comp sci\slot machine\slotmachine.java:21: ';' expected win.setFont(new Font("Serif", Font.BOLD, 42)); ^E:\adv. comp sci\slot machine\slotmachine.java:21: illegal start of type win.setFont(new Font("Serif", Font.BOLD, 42)); ^E:\adv. comp sci\slot machine\slotmachine.java:21: <identifier> expected win.setFont(new Font("Serif", Font.BOLD, 42)); ^E:\adv. comp sci\slot machine\slotmachine.java:21: illegal start of type win.setFont(new Font("Serif", Font.BOLD, 42)); ^E:\adv. comp sci\slot machine\slotmachine.java:21: <identifier> expected win.setFont(new Font("Serif", Font.BOLD, 42)); ^E:\adv. comp sci\slot machine\slotmachine.java:22: <identifier> expected win.setForeground(Color.red); ^E:\adv. comp sci\slot machine\slotmachine.java:22: <identifier> expected win.setForeground(Color.red); ^13 errorsProcess completed.
import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.util.Random;import java.util.*;public class slotmachine extends JApplet implements ActionListener { Random r = new Random(); JButton spin = new JButton("Spin!"); JLabel slot11,slot12,slot13,slot21,slot22,slot23,slot31,slot32,slot33; JLabel win = new JLabel("YOU WIN!"); win.setFont(new Font("Serif", Font.BOLD, 42)); win.setForeground(Color.red); JLabel lose = new JLabel("YOU LOSE!"); Container contentArea; Graphics g; public void init() { contentArea = getContentPane(); contentArea.setBackground(Color.cyan); FlowLayout manager = new FlowLayout(); contentArea.setLayout(manager); spin.addActionListener(this); spin.setEnabled(true); contentArea.add(spin); setContentPane(contentArea); } public void actionPerformed(ActionEvent event) { Image limon = getImage(getCodeBase(),"limon.jpg"); ImageIcon pica = new ImageIcon(limon); Image grape = getImage(getCodeBase(),"grape.jpg"); ImageIcon picb = new ImageIcon(grape); Image johnnydepp = getImage(getCodeBase(),"johnnydepp.jpg"); ImageIcon picc = new ImageIcon(johnnydepp); if(event.getSource()==spin) { int randomnumber1 = r.nextInt(3)+1; int randomnumber2 = r.nextInt(3)+1; int randomnumber3 = r.nextInt(3)+1; slot11 = new JLabel(pica); slot12 = new JLabel(picb); slot13 = new JLabel(picc); slot21 = new JLabel(pica); slot22 = new JLabel(picb); slot23 = new JLabel(picc); slot31 = new JLabel(pica); slot32 = new JLabel(picb); slot33 = new JLabel(picc); contentArea.removeAll(); setContentPane(contentArea); if (randomnumber1 == 1) { contentArea.add(slot11); contentArea.add(spin); setContentPane(contentArea); } if (randomnumber1 == 2) { contentArea.add(slot12); contentArea.add(spin); setContentPane(contentArea); } if (randomnumber1 == 3) { contentArea.add(slot13); contentArea.add(spin); setContentPane(contentArea); } if (randomnumber2 == 1) { contentArea.add(slot21); contentArea.add(spin); setContentPane(contentArea); } if (randomnumber2 == 2) { contentArea.add(slot22); contentArea.add(spin); setContentPane(contentArea); } if (randomnumber2 == 3) { contentArea.add(slot23); contentArea.add(spin); setContentPane(contentArea); } if (randomnumber3 == 1) { contentArea.add(slot31); contentArea.add(spin); setContentPane(contentArea); } if (randomnumber3 == 2) { contentArea.add(slot32); contentArea.add(spin); setContentPane(contentArea); } if (randomnumber3 == 3) { contentArea.add(slot33); contentArea.add(spin); setContentPane(contentArea); } if ((randomnumber1 == 1 && randomnumber2 == 1 && randomnumber3 == 1) || (randomnumber1 == 2 && randomnumber2 == 2 && randomnumber3 == 2) || (randomnumber1 == 3 && randomnumber2 == 3 && randomnumber3 == 3)) { contentArea.add(win); setContentPane(contentArea); } else { contentArea.add(lose); setContentPane(contentArea); } } }}