Hi this is a decompiled version of a guessing game which i am required to submit in assignment. can anyone please make it run anyhow. i hav also attached sample from which i generated code any help will be appreciated. Thanks
// Decompiled by DJ v3.11.11.95 Copyright 2009 Atanas Neshkov Date: 2/09/2009 5:40:48 PM
// Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: GuessingGame.java
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class GuessingGame extends JFrame
{
public GuessingGame()
{
credit = 20;
yourOptionValue = 0;
computerChoice = 0;
outputMessage = "";
higherOrLower = "";
computerChoice = generateNumber();
JMenuBar jmenubar = new JMenuBar();
setJMenuBar(jmenubar);
jmenubar.add(createFileMenu());
jmenubar.add(createHelpMenu());
JPanel jpanel = createLeftPanel();
JPanel jpanel1 = createRightPanel();
JPanel jpanel2 = new JPanel();
jpanel2.setLayout(new GridLayout(1, 2));
jpanel2.setBorder(new TitledBorder(new EtchedBorder(), ""));
jpanel2.add(jpanel);
jpanel2.add(jpanel1);
add(jpanel2);
}
public JMenu createFileMenu()
{
JMenu jmenu = new JMenu("File");
jmenu.add(createExitItem());
return jmenu;
}
public JMenuItem createExitItem()
{
JMenuItem jmenuitem = new JMenuItem("Exit");
class _cls1MenuItemListener
implements ActionListener
{
public void actionPerformed(ActionEvent actionevent)
{
if(JOptionPane.showConfirmDialog(null, "DO YOU REALLY WANT TO EXIT??", "", 0, 2) == 0)
System.exit(0);
}
final GuessingGame this$0;
_cls1MenuItemListener()
{
this$0 = GuessingGame.this;
super();
}
}
_cls1MenuItemListener _lcls1menuitemlistener = new _cls1MenuItemListener();
jmenuitem.addActionListener(_lcls1menuitemlistener);
return jmenuitem;
}
public JMenu createHelpMenu()
{
JMenu jmenu = new JMenu("Help");
jmenu.add(createAboutItem());
return jmenu;
}
public JMenuItem createAboutItem()
{
JMenuItem jmenuitem = new JMenuItem("About");
class _cls2MenuItemListener
implements ActionListener
{
public void actionPerformed(ActionEvent actionevent)
{
JOptionPane.showMessageDialog(null, "Input a number between 0-20 in the Lucky Guess Area, press Start button.");
}
final GuessingGame this$0;
_cls2MenuItemListener()
{
this$0 = GuessingGame.this;
super();
}
}
_cls2MenuItemListener _lcls2menuitemlistener = new _cls2MenuItemListener();
jmenuitem.addActionListener(_lcls2menuitemlistener);
return jmenuitem;
}
public JPanel createLeftPanel()
{
textArea = new JTextArea(25, 30);
JScrollPane jscrollpane = new JScrollPane(textArea);
textArea.setText("");
textArea.setEditable(false);
JPanel jpanel = new JPanel();
jpanel.add(jscrollpane);
jpanel.setBorder(new TitledBorder(new EtchedBorder(), "Output Message area"));
return jpanel;
}
public JPanel createRightPanel()
{
JPanel jpanel = new JPanel(new GridLayout(1, 1));
jpanel.setBorder(new TitledBorder(new EtchedBorder(), "Credit Point Area"));
creditLabel = new JLabel((new StringBuilder()).append("Your Current Credit: ").append(credit).toString());
jpanel.add(creditLabel);
JPanel jpanel1 = createCoinPanel();
JPanel jpanel2 = createInputPanel();
JPanel jpanel3 = createFunctionPanel();
JPanel jpanel4 = new JPanel(new GridLayout(4, 1));
jpanel4.add(jpanel);
jpanel4.add(jpanel1);
jpanel4.add(jpanel2);
jpanel4.add(jpanel3);
return jpanel4;
}
public JPanel createCoinPanel()
{
JPanel jpanel = new JPanel(new GridLayout(1, 2));
jpanel.setBorder(new TitledBorder(new EtchedBorder(), "Insert Coin"));
oneDollar = new JRadioButton("$1");
twoDollar = new JRadioButton("$2");
oneDollar.setEnabled(false);
twoDollar.setEnabled(false);
ButtonGroup buttongroup = new ButtonGroup();
buttongroup.add(oneDollar);
buttongroup.add(twoDollar);
class _cls1CoinListener
implements ActionListener
{
public void actionPerformed(ActionEvent actionevent)
{
String s = actionevent.getActionCommand();
if(s.equals("$1"))
credit = credit + 10;
if(s.equals("$2"))
credit = credit + 20;
creditLabel.setText((new StringBuilder()).append("Your Current Credit: ").append(credit).toString());
setGameEnabled(true);
setMoneyEnabled(false);
}
final GuessingGame this$0;
_cls1CoinListener()
{
this$0 = GuessingGame.this;
super();
}
}
_cls1CoinListener _lcls1coinlistener = new _cls1CoinListener();
oneDollar.addActionListener(_lcls1coinlistener);
twoDollar.addActionListener(_lcls1coinlistener);
jpanel.add(oneDollar);
jpanel.add(twoDollar);
return jpanel;
}
public JPanel createInputPanel()
{
JPanel jpanel = new JPanel(new GridLayout(2, 1));
jpanel.setBorder(new TitledBorder(new EtchedBorder(), "Lucky Guess Area"));
JLabel jlabel = new JLabel("Enter a number from 0 to 20 then press Start");
guessTextField = new JTextField(3);
guessTextField.setEditable(true);
jpanel.add(jlabel);
jpanel.add(guessTextField);
return jpanel;
}
public JPanel createFunctionPanel()
{
JPanel jpanel = new JPanel(new GridLayout(1, 2));
jpanel.setBorder(new TitledBorder(new EtchedBorder(), "Function Panel"));
start = new JButton("START");
reset = new JButton("RESET");
class _cls1FunctionListener
implements ActionListener
{
public void actionPerformed(ActionEvent actionevent)
{
String s = actionevent.getActionCommand();
String s1 = "Yes";
if(s.equals("RESET"))
reset();
if(s.equals("START"))
{
try
{
yourOptionValue = Integer.parseInt(guessTextField.getText());
}
catch(NumberFormatException numberformatexception)
{
JOptionPane.showMessageDialog(null, "Please enter an integer value in the field!");
guessTextField.setText("");
s1 = "No";
}
if(yourOptionValue < 0 || yourOptionValue > 20)
{
JOptionPane.showMessageDialog(null, "Please enter an integer between 0-20!");
guessTextField.setText("");
s1 = "No";
}
if(s1 == "Yes")
{
int i = getCreditEarn(yourOptionValue, computerChoice);
credit = credit + i;
outputMessage = (new StringBuilder()).append(outputMessage).append("You guessed: ").append(yourOptionValue).append("\tComputer guessed: ").append(getHigherOrLower(yourOptionValue, computerChoice)).append("\n").toString();
textArea.setText(outputMessage);
creditLabel.setText((new StringBuilder()).append("Your Current Credit: ").append(credit).toString());
}
if(credit < 10)
{
JOptionPane.showMessageDialog(null, "You'v lost, insert coin to continue");
setGameEnabled(false);
setMoneyEnabled(true);
}
if(credit >= 50)
{
JOptionPane.showMessageDialog(null, "You won!!");
reset();
}
}
}
final GuessingGame this$0;
_cls1FunctionListener()
{
this$0 = GuessingGame.this;
super();
}
}
_cls1FunctionListener _lcls1functionlistener = new _cls1FunctionListener();
start.addActionListener(_lcls1functionlistener);
reset.addActionListener(_lcls1functionlistener);
jpanel.add(start);
jpanel.add(reset);
return jpanel;
}
public int getCreditEarn(int i, int j)
{
int k = 0;
if(i > j || i < j)
k -= 2;
else
k += 50;
return k;
}
public String getHigherOrLower(int i, int j)
{
if(i > j)
return "Lower";
if(i < j)
return "Higher";
else
return "Same";
}
public void reset()
{
computerChoice = generateNumber();
yourOptionValue = 0;
credit = 20;
outputMessage = "";
textArea.setText("");
creditLabel.setText((new StringBuilder()).append("Your Current Credit: ").append(credit).toString());
guessTextField.setText("");
setGameEnabled(true);
setMoneyEnabled(false);
}
public void setGameEnabled(boolean flag)
{
start.setEnabled(flag);
}
public void setMoneyEnabled(boolean flag)
{
oneDollar.setEnabled(flag);
twoDollar.setEnabled(flag);
}
public int generateNumber()
{
Random random = new Random();
return 1 + random.nextInt(20);
}
public static void main(String args[])
{
GuessingGame guessinggame = new GuessingGame();
guessinggame.setDefaultCloseOperation(3);
guessinggame.setSize(700, 500);
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int i = dimension.width;
int j = dimension.height;
int k = (i - guessinggame.getWidth()) / 2;
int l = (j - guessinggame.getHeight()) / 2;
guessinggame.setLocation(k, l);
guessinggame.setVisible(true);
guessinggame.setResizable(false);
}
private int credit;
private int yourOptionValue;
private int computerChoice;
private String outputMessage;
private String higherOrLower;
private JTextArea textArea;
private JLabel creditLabel;
private JRadioButton oneDollar;
private JRadioButton twoDollar;
private JTextField guessTextField;
private JButton start;
private JButton reset;
private static final int FRAME_WIDTH = 700;
private static final int FRAME_HEIGHT = 500;
}